Created
March 3, 2018 22:13
-
-
Save mohnoor94/5ef0e2e436b891c243b6802fcc072c84 to your computer and use it in GitHub Desktop.
Functional Programming Principles in Scala - Exercise 3: Counting Change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Exercise 3 | |
| */ | |
| def countChange(money: Int, coins: List[Int]): Int = { | |
| if (money == 0) 1 | |
| else if (money < 0 || coins.isEmpty) 0 | |
| else countChange(money - coins.head, coins) + countChange(money, coins.tail) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This exercise is copied from the Functional Programming Principles in Scala course, week 1. Find more on my website.