2019-07-16 23:09:53 +00:00
|
|
|
|
"""
|
2018-10-17 02:41:33 +00:00
|
|
|
|
Coin sums
|
2020-10-10 15:53:17 +00:00
|
|
|
|
Problem 31: https://projecteuler.net/problem=31
|
|
|
|
|
|
2018-10-17 02:41:33 +00:00
|
|
|
|
In England the currency is made up of pound, £, and pence, p, and there are
|
|
|
|
|
eight coins in general circulation:
|
|
|
|
|
|
|
|
|
|
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
|
|
|
|
|
It is possible to make £2 in the following way:
|
|
|
|
|
|
|
|
|
|
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
|
|
|
|
|
How many different ways can £2 be made using any number of coins?
|
2019-07-16 23:09:53 +00:00
|
|
|
|
"""
|
2019-10-05 05:14:13 +00:00
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def one_pence() -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def two_pence(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else two_pence(x - 2) + one_pence()
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def five_pence(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else five_pence(x - 5) + two_pence(x)
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def ten_pence(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else ten_pence(x - 10) + five_pence(x)
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def twenty_pence(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else twenty_pence(x - 20) + ten_pence(x)
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def fifty_pence(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else fifty_pence(x - 50) + twenty_pence(x)
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def one_pound(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else one_pound(x - 100) + fifty_pence(x)
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def two_pound(x: int) -> int:
|
2018-10-17 02:41:33 +00:00
|
|
|
|
return 0 if x < 0 else two_pound(x - 200) + one_pound(x)
|
|
|
|
|
|
|
|
|
|
|
2020-10-10 15:53:17 +00:00
|
|
|
|
def solution(n: int = 200) -> int:
|
2020-04-25 21:27:01 +00:00
|
|
|
|
"""Returns the number of different ways can n pence be made using any number of
|
2019-07-16 23:09:53 +00:00
|
|
|
|
coins?
|
|
|
|
|
|
|
|
|
|
>>> solution(500)
|
|
|
|
|
6295434
|
|
|
|
|
>>> solution(200)
|
|
|
|
|
73682
|
|
|
|
|
>>> solution(50)
|
|
|
|
|
451
|
|
|
|
|
>>> solution(10)
|
|
|
|
|
11
|
|
|
|
|
"""
|
|
|
|
|
return two_pound(n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-10-10 15:53:17 +00:00
|
|
|
|
print(solution(int(input().strip())))
|