Advertisement
Guest User

Untitled

a guest
May 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.47 KB | None | 0 0
  1. /**
  2.     * Exercise 3
  3.     */
  4.   def countChange(money: Int, coins: List[Int]): Int = {
  5.     def iterator(money: Int, coins: List[Int], acc: Int = 0): Int = {
  6.       if (!coins.isEmpty) {
  7.         val rest = money - coins.head
  8.  
  9.         if (rest > 0) iterator(money, coins.tail, iterator(rest, coins, acc))
  10.         else if (rest == 0) iterator(money, coins.tail, acc + 1)
  11.         else iterator(money, coins.tail, acc)
  12.  
  13.       } else acc
  14.     }
  15.    
  16.     iterator(money, coins)
  17.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement