Created
March 8, 2015 23:50
-
-
Save jacks205/4cedc38f80ad0b841ed9 to your computer and use it in GitHub Desktop.
Script to find how many palindromic numbers there are in a set representable by a 16 bit unsigned integer
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
def main(): | |
# length of unsigned 16 bit int | |
length = 65535 | |
# keep count of how many palindromic numbers there are | |
count = 0 | |
# loop through entire range | |
for i in range(0,length): | |
#cast i to a string and compare reverse | |
if(str(i) == reverseString(str(i))): | |
count += 1 | |
# for a 16 bit unsigned int, the answer is 754 | |
print count | |
def reverseString(string): | |
return string[::-1] | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment