-
Notifications
You must be signed in to change notification settings - Fork 0
/
17.py
27 lines (18 loc) · 768 Bytes
/
17.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from itertools import combinations
from util import flatten, array, readinput
def solve(data, total):
all_combs = [list(combinations(data, r)) for r in range(len(data))]
return len([c for c in list(flatten(all_combs)) if sum(c) == total])
def solve2(data, total):
all_combs = [list(combinations(data, r)) for r in range(len(data))]
return len(list(filter(lambda x: len(x) > 0,
[[c for c in c_r if sum(c) == total]
for c_r in all_combs]))[0])
def tests():
assert solve([20, 15, 10, 5, 5], 25) == 4
assert solve2([20, 15, 10, 5, 5], 25) == 3
print('tests pass')
tests()
STORAGE = [line[0] for line in array(readinput(17))]
print(solve(STORAGE, 150))
print(solve2(STORAGE, 150))