Skip to content

Instantly share code, notes, and snippets.

@alexzobi
Last active May 7, 2018 12:50
Show Gist options
  • Save alexzobi/e3271431349c7e6adaa3fc4cb40c1a42 to your computer and use it in GitHub Desktop.
Save alexzobi/e3271431349c7e6adaa3fc4cb40c1a42 to your computer and use it in GitHub Desktop.
coins - recursive
function change(amount, coins, idx) {
if (idx >= coins.length -1) return 1;
let coin = coins[idx];
let combos = 0;
for (let i=0; i * coin <= amount; i++){
let amountRemaining = amount - i * coin;
console.log('i',i)
console.log('coin', coin)
console.log('remaining', amountRemaining)
combos += change(amountRemaining, coins, idx + 1);
console.log('combos', combos)
}
return combos;
}
change(25,[25,10,5,1],0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment