projecteuler

My solutions to various problems from projecteuler.net
git clone https://github.com/michaelneuper/projecteuler.git
README | Files | Log | Refs

commit f15b33e7121a9a8bb0c7b4062d9f8b804c20c9a3
parent 0d9d853424661aa302c05c2ec23380b25afed5aa
Author: Michael Neuper <michael@michaelneuper.com>
Date:   Wed,  6 Nov 2024 19:48:03 +0200

add problem 31

Diffstat:
Mproblem031/main.py | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/problem031/main.py b/problem031/main.py @@ -0,0 +1,16 @@ +coins = [1, 2, 5, 10, 20, 50, 100, 200] + +def get_subsets(lst): + if not lst: return [[]] + + first, rest = lst[0], lst[1:] + + subsets_without_first = get_subsets(rest) + subsets_with_first = [[first] + subset for subset in subsets_without_first] + + return subsets_without_first + subsets_with_first + +# 200p +subsets = get_subsets(coins) +subsets200 = [subset for subset in subsets if sum(subset) == 200] +print(subsets200)