Created
July 25, 2012 16:37
-
-
Save azmfaridee/3177124 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 reverse(a): | |
b = 0 | |
while a > 0: | |
b = b * 10 + (a % 10) | |
a /= 10 | |
return b | |
def check(a, b): | |
while (a > 0) and (b > 0): | |
c = a % 10 | |
d = b % 10 | |
if c != d: | |
return False | |
a = a / 10 | |
b = b / 10 | |
return True | |
num = 195 | |
n = 0 | |
while True: | |
rev = reverse(num) | |
if check(num, rev) == True: | |
break; | |
n += 1 | |
num = rev + num | |
print num, n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment