Created
December 1, 2014 14:02
-
-
Save tomasos/1647d7d1ad8e3b0b93d2 to your computer and use it in GitHub Desktop.
Find numbers that are palindrome in both base 8 and base 10
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
function palindrome(number) { | |
n = number; | |
rev = 0; | |
while (number > 0) | |
{ | |
dig = number % 10; | |
rev = rev * 10 + dig; | |
number = Math.floor(number / 10); | |
} | |
return n === rev; | |
} | |
function findPalindromes(max) { | |
var result = 0; | |
for(var i = 1; i < max; i++) { | |
if(palindrome(i) && palindrome(parseInt(i.toString(8)))) { | |
result = result + 1; | |
} | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment