Created
March 10, 2014 22:49
-
-
Save DanBrink91/9476080 to your computer and use it in GitHub Desktop.
Pure number palindrome, no string or array
This file contains 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
n = [121, 100, 1337, 404, 33] | |
def num_digits(n): | |
digits = 0 | |
while n > 0: | |
n /= 10 | |
digits+= 1 | |
return digits | |
def is_palindrome(n): | |
digits = num_digits(n) | |
for x in xrange(digits/2): | |
if (n/(10**(digits-x-1)))%10 != (n/(10**(x)))%10: | |
return False | |
return True | |
#print is_palindrome(n[2]) | |
for num in n: | |
print is_palindrome(num) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment