Skip to content

Instantly share code, notes, and snippets.

@nicola88
Created March 19, 2019 14:27
Show Gist options
  • Select an option

  • Save nicola88/db2115dfc1d078464346b58383e8540b to your computer and use it in GitHub Desktop.

Select an option

Save nicola88/db2115dfc1d078464346b58383e8540b to your computer and use it in GitHub Desktop.
Functional programming principles with Scala
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