mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 05:40:32 +01:00
Solution to day 24.
This commit is contained in:
28
day-24/input.txt
Normal file
28
day-24/input.txt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
1
|
||||||
|
3
|
||||||
|
5
|
||||||
|
11
|
||||||
|
13
|
||||||
|
17
|
||||||
|
19
|
||||||
|
23
|
||||||
|
29
|
||||||
|
31
|
||||||
|
41
|
||||||
|
43
|
||||||
|
47
|
||||||
|
53
|
||||||
|
59
|
||||||
|
61
|
||||||
|
67
|
||||||
|
71
|
||||||
|
73
|
||||||
|
79
|
||||||
|
83
|
||||||
|
89
|
||||||
|
97
|
||||||
|
101
|
||||||
|
103
|
||||||
|
107
|
||||||
|
109
|
||||||
|
113
|
||||||
20
day-24/solution.py
Normal file
20
day-24/solution.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from __future__ import print_function, division
|
||||||
|
import fileinput
|
||||||
|
import itertools
|
||||||
|
import functools
|
||||||
|
import operator
|
||||||
|
|
||||||
|
def qes(packageList):
|
||||||
|
return functools.reduce(operator.mul, packageList)
|
||||||
|
|
||||||
|
def minQES(packages, slots):
|
||||||
|
targetWeight = sum(packages) // slots
|
||||||
|
for i in range(1, len(packages)):
|
||||||
|
solutions = [x for x in itertools.combinations(packages, i) if sum(x) == targetWeight]
|
||||||
|
if len(solutions) > 0:
|
||||||
|
return min(qes(x) for x in solutions)
|
||||||
|
|
||||||
|
packages = set([int(x) for x in fileinput.input()])
|
||||||
|
|
||||||
|
print(minQES(packages, 3))
|
||||||
|
print(minQES(packages, 4))
|
||||||
Reference in New Issue
Block a user