Created
September 17, 2014 04:34
-
-
Save dz1984/cf84c8307c6d44ae15ef to your computer and use it in GitHub Desktop.
Implement the exercise 3: Counting Change on "Functional Programming Principles in Scala" course via CoffeeScript.
This file contains 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
countChange = (money, coins) -> | |
_targetMoney = money | |
loops = (_currentMoney, _canUsedCoins) -> | |
return 0 if (_.isEmpty(_canUsedCoins)) | |
h = _.head _canUsedCoins | |
t = _.tail _canUsedCoins | |
newMoney = _currentMoney + h | |
return 0 if newMoney > _targetMoney | |
return 1 if newMoney == _targetMoney | |
loops(newMoney, _canUsedCoins) + loops(_currentMoney, t) | |
loops(0, coins) | |
console.log countChange(5,[1,2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment