Last active
August 29, 2015 14:11
-
-
Save maakuth/6c880f68cf36ec05dfd6 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def isPalindrome(whatever): | |
reverse = '' | |
for c in whatever: | |
reverse = c + reverse | |
return reverse == whatever | |
m = 0 | |
n = 999999 | |
print ("Testing palindromeness for %d to %d" % (m, n)) | |
matches = [] | |
for i in range(m, n): | |
if isPalindrome(str(i)) and isPalindrome(str(bin(i))[2:]): | |
matches.append(i) | |
print ("Matching:") | |
for match in matches: | |
print ("%s == %s " % (str(match), str(bin(match)))) |
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
Testing palindromeness for 0 to 999999 | |
Matching: | |
0 == 0b0 | |
1 == 0b1 | |
3 == 0b11 | |
5 == 0b101 | |
7 == 0b111 | |
9 == 0b1001 | |
33 == 0b100001 | |
99 == 0b1100011 | |
313 == 0b100111001 | |
585 == 0b1001001001 | |
717 == 0b1011001101 | |
7447 == 0b1110100010111 | |
9009 == 0b10001100110001 | |
15351 == 0b11101111110111 | |
32223 == 0b111110111011111 | |
39993 == 0b1001110000111001 | |
53235 == 0b1100111111110011 | |
53835 == 0b1101001001001011 | |
73737 == 0b10010000000001001 | |
585585 == 0b10001110111101110001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment