I just heard an old episode of "Car Talks" and they gave the following puzzle:
http://www.mscs.mu.edu/~paulb/Puzzle/palindromesolution.html
I wanted to see how quickly I could solve it in python without attempting to be efficient and ended up with this:
#puzzler #7 solver #written by jim clampffer 4/29/13 #string -> bool def ispalendrome(numberstring): return numberstring == numberstring[::-1] for milenum in range(999999): mile = str(milenum).zfill(6) #check that last 4 digits but not last 5 digits are palendromic if not ispalendrome(mile[2:]) or ispalendrome(mile[1:]): continue #check that last 5 digits of mile + 1 are a palendrome mile = str(milenum+1).zfill(6) if not ispalendrome(mile[1:]): continue #check that middle 4 digits of mile + 2 are a palendrome mile = str(milenum+2).zfill(6) if not ispalendrome(mile[1:-1]): continue #check that all digits of mile + 3 are a palendrome mile = str(milenum+3).zfill(6) if not ispalendrome(mile): continue #got the answer print(milenum)
It worked. Cool.