Skip to content

Instantly share code, notes, and snippets.

@mariomelchor
Created January 30, 2018 05:03
Show Gist options
  • Save mariomelchor/9d99c241706b09feaf09d6eeead73d2a to your computer and use it in GitHub Desktop.
Save mariomelchor/9d99c241706b09feaf09d6eeead73d2a to your computer and use it in GitHub Desktop.
cubeSumSearch(1729);
function cubeSumSearch(n) {
var total = n;
for(var i = 0; i <= n; i++){
for(var j = i; j <= n; j++){
var sum = Math.pow(i, 3) + Math.pow(j, 3);
if( sum === total ){
console.log('-------------------------');
console.log(`${Math.pow(i, 3)} + ${Math.pow(j, 3)} = ${sum}`);
console.log(`${i}^3 + ${j}^3 = ${sum}`);
console.log('-------------------------');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment