Skip to content

Instantly share code, notes, and snippets.

@amejiarosario
Created January 10, 2020 23:48
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 amejiarosario/90512b1a6489d97e9b24439c10a4fdf7 to your computer and use it in GitHub Desktop.
Save amejiarosario/90512b1a6489d97e9b24439c10a4fdf7 to your computer and use it in GitHub Desktop.
function findXYZ(n) {
const solutions = [];
for(let x = 0; x < n; x++) {
for(let y = 0; y < n; y++) {
for(let z = 0; z < n; z++) {
if( 3*x + 9*y + 8*z === 79 ) {
solutions.push({x, y, z});
}
}
}
}
return solutions;
}
console.log(findXYZ(10)); // => [{x: 0, y: 7, z: 2}, ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment