Last active
August 29, 2015 14:08
-
-
Save briandk/96923f6a591dbc546baf to your computer and use it in GitHub Desktop.
Cantor's Diagonal Proof Code
This file contains 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
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