Created
March 19, 2019 14:27
-
-
Save nicola88/db2115dfc1d078464346b58383e8540b to your computer and use it in GitHub Desktop.
Functional programming principles with Scala
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
| from typing import List | |
| def count_change(money: int, coins: List[int]): | |
| if money == 0: | |
| return 1 | |
| # Amount > 0 | |
| if len(coins) == 0: | |
| return 0 | |
| # Amount > 0, 1+ coins | |
| coin = coins[0] | |
| if money < coin: | |
| return count_change(money, coins[1:]) | |
| else: | |
| return count_change(money, coins[1:]) + count_change(money - coins[0], coins) | |
| print(count_change(5,[5,2,1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment