Skip to content

Instantly share code, notes, and snippets.

@azmfaridee
Created July 25, 2012 16:37
Show Gist options
  • Save azmfaridee/3177124 to your computer and use it in GitHub Desktop.
Save azmfaridee/3177124 to your computer and use it in GitHub Desktop.
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