From 3f999eb382c3627154cb0dacd8abda695aba1519 Mon Sep 17 00:00:00 2001 From: tingleshao Date: Mon, 11 Mar 2013 11:53:57 -0400 Subject: [PATCH] problem 55 --- problem51to60/problem53.py | 2 ++ problem51to60/problem55.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 problem51to60/problem55.py diff --git a/problem51to60/problem53.py b/problem51to60/problem53.py index bd15af1..add6af1 100644 --- a/problem51to60/problem53.py +++ b/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)) diff --git a/problem51to60/problem55.py b/problem51to60/problem55.py new file mode 100644 index 0000000..61d832d --- /dev/null +++ b/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 +