Solve 2015 days 11-18.
This commit is contained in:
26
2015/d17.py
Normal file
26
2015/d17.py
Normal 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
|
||||
Reference in New Issue
Block a user