Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.54 KB | None | 0 0
  1.  
  2.  
  3. def countChange(money: Int, coins: List[Int]): Int = {
  4.     def countAcross(money: Int, coins: List[Int], index: Int): Int = {
  5.         if(index < coins.length)
  6.             countVertical(money - coins(index), coins, index) +
  7.             countAcross(money, coins, index + 1)
  8.         else
  9.             0
  10.  
  11.     }
  12.  
  13.     def countVertical(money: Int, coins: List[Int], index: Int): Int = {
  14.         if(money == 0)
  15.             1
  16.         else if(money < 0)
  17.             0
  18.         else
  19.             countVertical(money - coins(index), coins, index) +
  20.             countAcross(money, coins, index + 1)
  21.  
  22.     }
  23.  
  24.     countVertical(money, coins, 0)
  25.    
  26.    
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement