Created
May 11, 2018 14:26
-
-
Save beatak/55b4c71bc66582fd62abeb1585e2cb0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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