Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Exercise 3
- */
- def countChange(money: Int, coins: List[Int]): Int = {
- def iterator(money: Int, coins: List[Int], acc: Int = 0): Int = {
- if (!coins.isEmpty) {
- val rest = money - coins.head
- if (rest > 0) iterator(money, coins.tail, iterator(rest, coins, acc))
- else if (rest == 0) iterator(money, coins.tail, acc + 1)
- else iterator(money, coins.tail, acc)
- } else acc
- }
- iterator(money, coins)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement