Skip to content

Instantly share code, notes, and snippets.

@agrif
Created October 22, 2019 16:28
Show Gist options
  • Save agrif/b89c450a83196b3655b04fb07c9f9fb5 to your computer and use it in GitHub Desktop.
Save agrif/b89c450a83196b3655b04fb07c9f9fb5 to your computer and use it in GitHub Desktop.
a crappy python proof that the halting problem is unsolvable
def halts(f, x):
# returns True if f(x) halts
# False if it runs forever
# notably, to solve the halting problem, it *must* return either True or False
# it can't just run forever...
return magic_turing_oracle(f, x)
def sneaky(f):
# see if f halts when passed itself as input...
if halts(f, f):
# f halts, so we shouldn't
while True: pass
else:
# f doesn't halt, so we should
return
# what on *earth* does this do?
print(halts(sneaky, sneaky))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment