Created
July 24, 2018 20:39
-
-
Save f0ster/56dbb5408a56eac97d87a92457bdd40b to your computer and use it in GitHub Desktop.
more scala recursive fun
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
/** | |
* Exercise 3 | |
*/ | |
def countChange(money: Int, coins: List[Int]): Int = { | |
def count(m: Int, sortedCoins: List[Int]) : Int = { | |
if (sortedCoins.isEmpty) 0 | |
else if (m - sortedCoins.head == 0) 1 | |
else if (m - sortedCoins.head < 0) 0 | |
else countChange(m - sortedCoins.head, sortedCoins) + countChange(m, sortedCoins.tail) | |
} | |
count(money, coins.sorted) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment