Skip to content

Commit

Permalink
Feat: Adds JS 036
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankKair committed Mar 1, 2019
1 parent 5b43c14 commit 663051c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/036/p036.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const palindrome = (s) => s === s.split('').reverse().join('');

const numberPalindrome = (n, base) => {
switch (base) {
case 2: return palindrome(n.toString(2));
case 10: return palindrome(n.toString());
default: return false;
}
}

const doubleBasePalindrome = (n) =>
numberPalindrome(n, 2) && numberPalindrome(n, 10);

const sumDoubleBasePalindromesBelow = (limit) => (
Array(limit)
.fill(0)
.map((_, i) => i + 1)
.filter(x => doubleBasePalindrome(x))
.reduce((sum, value) => sum + value)
);

const solve = () => sumDoubleBasePalindromesBelow(1000000);

const result = solve();
console.log(result);

0 comments on commit 663051c

Please sign in to comment.