Skip to content

Instantly share code, notes, and snippets.

@briandk
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandk/96923f6a591dbc546baf to your computer and use it in GitHub Desktop.
Save briandk/96923f6a591dbc546baf to your computer and use it in GitHub Desktop.
Cantor's Diagonal Proof Code
complement = {0: 1,
1: 0} # Maps 0 to 1 and vice versa
newNumber = [] # Initialize an empty list as a new number
def CantorDiagonal(MatrixOfAllNumbers, newNumber):
for i in range(len(MatrixOfAllNumbers)):
"""
Remember, the length of the matrix is infinite,
so this loop runs forever. It scans the diagonal
of the matrix by checking the entry at i, i.
Then, it creates a new digit for our new number
by taking the complement of the existing digit.
Finally, it constructs our new number by appending
the new digit.
"""
existingDigit = MatrixOfAllNumbers[i][i]
newDigit = complement[existingDigit]
newNumber.append(newDigit)
return(newNumber)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment