47 lines
1020 B
Python

#!/usr/bin/env python
"""
Created on 24 Feb 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 031 of Project Euler
https://projecteuler.net/problem=31
"""
from itertools import product
from utils import timeit
@timeit("Problem 031")
def compute():
"""
In the United Kingdom the currency is made up of pound (£) and pence (p).
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:
1x£1 + 1x50p + 2x20p + 1x5p + 1x2p + 3x1p
How many different ways can £2 be made using any number of coins?
"""
ans = 0
coins = [2, 5, 10, 20, 50, 100]
bunch_of_coins = product(*[range(0, 201, i) for i in coins])
for money in bunch_of_coins:
if sum(money) <= 200:
ans += 1
# consider also the case for 200 coins of 1p
return ans + 1
if __name__ == "__main__":
print(f"Result for Problem 031: {compute()}")