Skip to content

Instantly share code, notes, and snippets.

@jacks205
Created March 8, 2015 23:50
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 jacks205/4cedc38f80ad0b841ed9 to your computer and use it in GitHub Desktop.
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
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