Created
May 27, 2016 22:28
-
-
Save huttj/5f2c18e62f3a01d29ce4d1786ed50be6 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
'use strict'; | |
const coins = [100,25,10,5,1]; | |
const optimal = coinCount(48); | |
console.log(coinCount(25, without(coins, 25))); | |
console.log( | |
optimal.map(n => coinCount(n)).join('\n') | |
); | |
function coinCount(number, coins) { | |
coins = coins || [100,25,10,5,1]; | |
const used = []; | |
let head; | |
while (number > 0) { | |
head = coins[0]; | |
if (number >= head) { | |
number -= head; | |
used.push(head); | |
} else { | |
coins.shift(); | |
} | |
} | |
return used; | |
} | |
function sum(arry) { | |
return arry.reduce((a,b) => a + b, 0); | |
} | |
function factors(n, less) { | |
const all = []; | |
const f = coinCount(n, without(coins, n)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment