Skip to content

Instantly share code, notes, and snippets.

@tomasos
Created December 1, 2014 14:02
Show Gist options
  • Save tomasos/1647d7d1ad8e3b0b93d2 to your computer and use it in GitHub Desktop.
Save tomasos/1647d7d1ad8e3b0b93d2 to your computer and use it in GitHub Desktop.
Find numbers that are palindrome in both base 8 and base 10
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