From 5cd3b975ae3a949daad44f6a4c42e372fa4b56b1 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 29 Sep 2022 22:21:56 +0200 Subject: [PATCH] Adopted new convention from template --- src/Python/Problems001-050/Problem031.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Python/Problems001-050/Problem031.py b/src/Python/Problems001-050/Problem031.py index 7a0a3a6..1e458f6 100644 --- a/src/Python/Problems001-050/Problem031.py +++ b/src/Python/Problems001-050/Problem031.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python """ Created on 24 Feb 2021 @@ -10,6 +10,7 @@ https://projecteuler.net/problem=31 """ from itertools import product + from utils import timeit @@ -23,21 +24,22 @@ def compute(): 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? + """ - no_ways = 0 - + 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: - no_ways += 1 + ans += 1 + # consider also the case for 200 coins of 1p - return no_ways + 1 + return ans + 1 + if __name__ == "__main__": - - print(f"Result for Problem 31: {compute()}") \ No newline at end of file + print(f"Result for Problem 31 is {compute()}")