Last active
June 3, 2016 10:49
-
-
Save skaslev/c768daf6918610c12c7a1a43bbf9f21d to your computer and use it in GitHub Desktop.
Cantor's diagonal argument
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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