Solve 2015 days 11-18.

This commit is contained in:
2024-02-01 19:21:22 -05:00
parent 35a01f1f65
commit 147a4f1165
6 changed files with 195 additions and 1 deletions

26
2015/d17.py Normal file
View File

@@ -0,0 +1,26 @@
from itertools import combinations
data = open(0).read().strip()
cons = list(map(int, data.splitlines()))
part_1 = False
if part_1:
def count(n, cons):
if n == 0:
return 1
elif len(cons) == 0:
return 0
r = 0
first = cons[0]
r += count(n - first, cons[1:])
r += count(n, cons[1:])
return r
print(count(150, cons))
else:
r = 0
for i in range(1, len(cons) + 1):
for c in combinations(cons, i):
if sum(c) == 150:
r += 1
if r > 0:
print(i)
break