Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
more scala recursive fun
/**
* 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