Skip to content

Instantly share code, notes, and snippets.

@skaslev
Last active June 3, 2016 10:49
Show Gist options
  • Select an option

  • Save skaslev/c768daf6918610c12c7a1a43bbf9f21d to your computer and use it in GitHub Desktop.

Select an option

Save skaslev/c768daf6918610c12c7a1a43bbf9f21d to your computer and use it in GitHub Desktop.
Cantor's diagonal argument
# https://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument
def bits(n):
return list(int(x) for x in reversed(bin(n)[2:]))
def nth(lst, n):
if n < len(lst):
return lst[n]
return 0
def flip(n):
return (n + 1) % 2
N = 17
t = [bits(n) for n in xrange(N)]
print 'Possible enumeration of all infinite sequences of binary digits:'
print '\n'.join(str(row + [0, 0, 0] + ['...']) for row in t)
print '...'
print '\nEntry not in the table by Cantor\'s diagonal argument:'
print [flip(nth(row, n)) for n, row in enumerate(t)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment