Skip to content

Commit

Permalink
problem 55
Browse files Browse the repository at this point in the history
  • Loading branch information
tingleshao committed Mar 11, 2013
1 parent bcab818 commit 3f999eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions problem51to60/problem53.py
@@ -1,4 +1,6 @@
# problem 53
# straight forward solution is very fast
# time complexity: O(n^2 * n) = O(n^3)
def combin(n,r):
return frac(n) / ( frac(n-r) * frac(r))

Expand Down
21 changes: 21 additions & 0 deletions problem51to60/problem55.py
@@ -0,0 +1,21 @@
# problem 55
def is_palindrome(n):
orig_n = n
n_str = str(n)
n_rev = int(n_str[::-1])
for i in range(50):
sum = n_rev + n
if str(sum) == str(sum)[::-1]:
print str(orig_n)+ " is palindromic!"
return True
n = sum
n_rev = int(str(n)[::-1])
return False

count = 0
for i in range(1,10000):
if not is_palindrome(i):
count += 1

print count

0 comments on commit 3f999eb

Please sign in to comment.