Advertisement
Guest User

bob

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