fork(1) download
  1. object Main extends App {
  2. def countChange(money: Int, coins: List[Int]): Int = {
  3. def countChange_(money: Int, coins: List[Int]): Int = {
  4. if (coins.isEmpty) 0
  5. else {
  6. money compare 0 match {
  7. case 0 => 1
  8. case -1 => 0
  9. case _ => countChange(money, coins.tail) + countChange_(money - coins.head, coins)
  10. }
  11. }
  12. }
  13. countChange_(money, coins)
  14. }
  15.  
  16. println(countChange(20, List(1, 2, 5, 10)))
  17. }
Success #stdin #stdout 0.37s 382080KB
stdin
Standard input is empty
stdout
40