Created
November 6, 2016 16:53
-
-
Save nerdybeast/893e5cdd2d19359c317c36a9e2525cf0 to your computer and use it in GitHub Desktop.
Euler 4 - Largest Palindrome
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
'use strict'; | |
const MIN = 100; | |
const MAX = 999; | |
let largestPalindrome = 0; | |
let numOfPalindromes = 0; | |
let calculations = 0; | |
for(var i = MIN; i <= MAX; i++) { | |
for(var j = i; j <= MAX; j++) { | |
calculations++; | |
let product = i * j; | |
let productAsString = String(product); | |
let inverse = productAsString.split('').reverse().join(''); | |
if(productAsString === inverse) { | |
numOfPalindromes++; | |
if(product > largestPalindrome) largestPalindrome = product; | |
} | |
} | |
} | |
console.log('Calculations Processed =>', calculations); | |
console.log('Palindromes Found =>', numOfPalindromes); | |
console.log('Largest Palindrome =>', largestPalindrome); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment