## Posted By

a7xrturo on 11/16/13

# Favorite's Einstein Puzzle

/ Published in: Python

Favorite's Einstein Puzzle that given a three digit number that the hundred's digit differs from the one's digit by at least two always returns 1089.

`# introduction print print('This is a puzzle favored by Einstein. You will be asked to enter\n \a three digit number, where the hundred\'s digit differs from the\n \one\'s digit by at least two. The procedure will always yield 1089\n') res = input('Give me a number --> ') # checks if the user enters a valid numberwhile True:    if len(res) == 3 and res.isdigit() and abs(int(res[0]) - int(res[2])) >= 2:        difference = int(res) - int(res[::-1]) # value used later in calculations        break     else:        res = input('Give me a number --> ')  # checks to make a normal difference and not to get negativesif int(res) < int(res[::-1]):    difference = int(res[::-1]) - int(res) # show and make calculationsprint('For the number:', res, 'the reverse number is:', res[::-1]) print('The difference between', res, 'and', res[::-1], 'is', difference) print('The reverse difference is', str(difference)[::-1]) print('The sum of', str(difference), 'and the reverse difference', \      str(difference)[::-1], 'is', str(difference + int(str(difference)[::-1])))`