Last active
August 29, 2015 14:12
-
-
Save Whelton/1f1e66b1767d8cd737f7 to your computer and use it in GitHub Desktop.
James' ghetto year-binary-palindrome thing
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
// James' ghetto year-binary-palindrome thing | |
// Damn it @joemccann https://twitter.com/joemccann/status/550663311478763520 | |
// Changed from crazy decimal to binary function to .toString(2)on Mike McNally's most excellent tip: https://twitter.com/m5/status/550690684122845185 | |
// Loop through years, starting at 0 all the way to 2015 (happy new year) | |
for(var i = 0; i <= 2015; i++){ | |
// Get it's binary representation (it'll be a string yo) (thank you @m5) | |
var binaryYear = (i).toString(2); | |
// Check if odd, make appropriate offset of 0.5 if so | |
var offset = 0; | |
if(binaryYear.length%2==1) { | |
offset = 0.5; // Shock horror | |
} | |
// If it's an even, check if everything to left of center character matches the reverse of everything to right of center character | |
var left = binaryYear.substring(0, (binaryYear.length / 2 ) - offset); | |
var right = binaryYear.substring((binaryYear.length / 2 ) + offset); | |
// Reverse and compare, if matches, log that sucker | |
if (left === (right.split('').reverse().join('')) ) { | |
console.log( i+" : "+binaryYear ); | |
} | |
} |
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
1 : 1 | |
3 : 11 | |
5 : 101 | |
7 : 111 | |
9 : 1001 | |
15 : 1111 | |
17 : 10001 | |
21 : 10101 | |
27 : 11011 | |
31 : 11111 | |
33 : 100001 | |
45 : 101101 | |
51 : 110011 | |
63 : 111111 | |
65 : 1000001 | |
73 : 1001001 | |
85 : 1010101 | |
93 : 1011101 | |
99 : 1100011 | |
107 : 1101011 | |
119 : 1110111 | |
127 : 1111111 | |
129 : 10000001 | |
153 : 10011001 | |
165 : 10100101 | |
189 : 10111101 | |
195 : 11000011 | |
219 : 11011011 | |
231 : 11100111 | |
255 : 11111111 | |
257 : 100000001 | |
273 : 100010001 | |
297 : 100101001 | |
313 : 100111001 | |
325 : 101000101 | |
341 : 101010101 | |
365 : 101101101 | |
381 : 101111101 | |
387 : 110000011 | |
403 : 110010011 | |
427 : 110101011 | |
443 : 110111011 | |
455 : 111000111 | |
471 : 111010111 | |
495 : 111101111 | |
511 : 111111111 | |
513 : 1000000001 | |
561 : 1000110001 | |
585 : 1001001001 | |
633 : 1001111001 | |
645 : 1010000101 | |
693 : 1010110101 | |
717 : 1011001101 | |
765 : 1011111101 | |
771 : 1100000011 | |
819 : 1100110011 | |
843 : 1101001011 | |
891 : 1101111011 | |
903 : 1110000111 | |
951 : 1110110111 | |
975 : 1111001111 | |
1023 : 1111111111 | |
1025 : 10000000001 | |
1057 : 10000100001 | |
1105 : 10001010001 | |
1137 : 10001110001 | |
1161 : 10010001001 | |
1193 : 10010101001 | |
1241 : 10011011001 | |
1273 : 10011111001 | |
1285 : 10100000101 | |
1317 : 10100100101 | |
1365 : 10101010101 | |
1397 : 10101110101 | |
1421 : 10110001101 | |
1453 : 10110101101 | |
1501 : 10111011101 | |
1533 : 10111111101 | |
1539 : 11000000011 | |
1571 : 11000100011 | |
1619 : 11001010011 | |
1651 : 11001110011 | |
1675 : 11010001011 | |
1707 : 11010101011 | |
1755 : 11011011011 | |
1787 : 11011111011 | |
1799 : 11100000111 | |
1831 : 11100100111 | |
1879 : 11101010111 | |
1911 : 11101110111 | |
1935 : 11110001111 | |
1967 : 11110101111 | |
2015 : 11111011111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment