2015 day 17.
This commit is contained in:
parent
c1732baa0d
commit
5b07e73382
30
src/holt59/aoc/2015/day17.py
Normal file
30
src/holt59/aoc/2015/day17.py
Normal file
@ -0,0 +1,30 @@
|
||||
import sys
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
def iter_combinations(value: int, containers: list[int]) -> Iterator[tuple[int, ...]]:
|
||||
if value < 0:
|
||||
return
|
||||
|
||||
if value == 0:
|
||||
yield ()
|
||||
|
||||
for i in range(len(containers)):
|
||||
for combination in iter_combinations(
|
||||
value - containers[i], containers[i + 1 :]
|
||||
):
|
||||
yield (containers[i],) + combination
|
||||
|
||||
|
||||
containers = [int(c) for c in sys.stdin.read().split()]
|
||||
total = 25 if len(containers) <= 5 else 150
|
||||
|
||||
combinations = [combination for combination in iter_combinations(total, containers)]
|
||||
|
||||
answer_1 = len(combinations)
|
||||
print(f"answer 1 is {answer_1}")
|
||||
|
||||
min_containers = min(len(combination) for combination in combinations)
|
||||
|
||||
answer_2 = sum(1 for combination in combinations if len(combination) == min_containers)
|
||||
print(f"answer 2 is {answer_2}")
|
20
src/holt59/aoc/inputs/holt59/2015/day17.txt
Normal file
20
src/holt59/aoc/inputs/holt59/2015/day17.txt
Normal file
@ -0,0 +1,20 @@
|
||||
33
|
||||
14
|
||||
18
|
||||
20
|
||||
45
|
||||
35
|
||||
16
|
||||
35
|
||||
1
|
||||
13
|
||||
18
|
||||
13
|
||||
50
|
||||
44
|
||||
48
|
||||
6
|
||||
24
|
||||
41
|
||||
30
|
||||
42
|
5
src/holt59/aoc/inputs/tests/2015/day17.txt
Normal file
5
src/holt59/aoc/inputs/tests/2015/day17.txt
Normal file
@ -0,0 +1,5 @@
|
||||
20
|
||||
15
|
||||
10
|
||||
5
|
||||
5
|
Loading…
Reference in New Issue
Block a user