Skip to content

Instantly share code, notes, and snippets.

@mohnoor94
Created March 3, 2018 22:13
Show Gist options
  • Select an option

  • Save mohnoor94/5ef0e2e436b891c243b6802fcc072c84 to your computer and use it in GitHub Desktop.

Select an option

Save mohnoor94/5ef0e2e436b891c243b6802fcc072c84 to your computer and use it in GitHub Desktop.
Functional Programming Principles in Scala - Exercise 3: Counting Change
/**
* 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)
}
@mohnoor94
Copy link
Author

This exercise is copied from the Functional Programming Principles in Scala course, week 1. Find more on my website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment