Adopted new convention from template
This commit is contained in:
parent
3cd992b1b3
commit
5cd3b975ae
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
Created on 24 Feb 2021
|
Created on 24 Feb 2021
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ https://projecteuler.net/problem=31
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
from utils import timeit
|
from utils import timeit
|
||||||
|
|
||||||
|
|
||||||
@ -23,21 +24,22 @@ def compute():
|
|||||||
|
|
||||||
It is possible to make £2 in the following way:
|
It is possible to make £2 in the following way:
|
||||||
|
|
||||||
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
|
1x£1 + 1x50p + 2x20p + 1x5p + 1x2p + 3x1p
|
||||||
|
|
||||||
How many different ways can £2 be made using any number of coins?
|
How many different ways can £2 be made using any number of coins?
|
||||||
|
|
||||||
"""
|
"""
|
||||||
no_ways = 0
|
ans = 0
|
||||||
|
|
||||||
coins = [2, 5, 10, 20, 50, 100]
|
coins = [2, 5, 10, 20, 50, 100]
|
||||||
|
|
||||||
bunch_of_coins = product(*[range(0, 201, i) for i in coins])
|
bunch_of_coins = product(*[range(0, 201, i) for i in coins])
|
||||||
|
|
||||||
for money in bunch_of_coins:
|
for money in bunch_of_coins:
|
||||||
if sum(money) <= 200:
|
if sum(money) <= 200:
|
||||||
no_ways += 1
|
ans += 1
|
||||||
|
|
||||||
# consider also the case for 200 coins of 1p
|
# consider also the case for 200 coins of 1p
|
||||||
return no_ways + 1
|
return ans + 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print(f"Result for Problem 31 is {compute()}")
|
||||||
print(f"Result for Problem 31: {compute()}")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user