-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
38 lines (30 loc) · 953 Bytes
/
script.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
28
29
30
31
32
33
34
35
36
37
38
from GhostyUtils import aoc
import itertools
from math import prod
import sys
def package_groups(packages, target_weight):
min_size = sys.maxsize
for group_size in range(1, len(packages)):
if min_size < group_size:
break
for combo in itertools.combinations(packages, group_size):
if sum(combo) == target_weight:
min_size = group_size
yield combo
def qe(group):
return prod(group)
if __name__ == "__main__":
packages = tuple(map(int, aoc.read_lines()))
total_weight = sum(packages)
lowest_qe = sys.maxsize
for g in package_groups(packages, total_weight // 3):
g_qe = qe(g)
if g_qe < lowest_qe:
lowest_qe = g_qe
print(lowest_qe)
lowest_qe = sys.maxsize
for g in package_groups(packages, total_weight // 4):
g_qe = qe(g)
if g_qe < lowest_qe:
lowest_qe = g_qe
print(lowest_qe)