Skip to content

Instantly share code, notes, and snippets.

@i-van
Created August 29, 2016 14:23
Show Gist options
  • Select an option

  • Save i-van/90163e8a6ff48156cec0b893643acaae to your computer and use it in GitHub Desktop.

Select an option

Save i-van/90163e8a6ff48156cec0b893643acaae to your computer and use it in GitHub Desktop.
function algorithm(x, y, z, w) {
var n = 0;
for (var i = 0; i <= w / x; i++) {
for (var j = 0; j <= w / y; j++) {
for (var k = 0; k <= w / z; k++) {
console.log(i, j, k, '=', i * x + j * y + k * z);
if (i * x + j * y + k * z === w) {
n++;
}
}
}
}
return n;
}
var res = algorithm(10, 15, 25, 40);
console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment