Skip to content

Instantly share code, notes, and snippets.

@beatak
Created May 11, 2018 14:26
Show Gist options
  • Save beatak/55b4c71bc66582fd62abeb1585e2cb0a to your computer and use it in GitHub Desktop.
Save beatak/55b4c71bc66582fd62abeb1585e2cb0a to your computer and use it in GitHub Desktop.
const findCombination = function (totalMoney, priceA, priceB, totalHeads) {
const result = [];
let countA, countB;
for (let i = 0; i < totalHeads; ++i) {
countA = i;
countB = totalHeads - i;
if (totalMoney === (countA * priceA + countB * priceB)) {
result.push([countA, countB]);
}
}
return result;
}
console.log(findCombination(550, 30, 25, 19));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment