Skip to content

Instantly share code, notes, and snippets.

@nerdybeast
Created November 6, 2016 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdybeast/893e5cdd2d19359c317c36a9e2525cf0 to your computer and use it in GitHub Desktop.
Save nerdybeast/893e5cdd2d19359c317c36a9e2525cf0 to your computer and use it in GitHub Desktop.
Euler 4 - Largest Palindrome
'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