2015: d17: ex2: add solution
This commit is contained in:
parent
6b2144fd2e
commit
86cdf0c8b6
1 changed files with 34 additions and 0 deletions
34
2015/d17/ex2/ex2.py
Executable file
34
2015/d17/ex2/ex2.py
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
TOTAL_EGGNOG = 150
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: str) -> int:
|
||||||
|
def parse(input: str) -> list[int]:
|
||||||
|
return [int(line) for line in input.splitlines()]
|
||||||
|
|
||||||
|
containers = parse(input)
|
||||||
|
min_containers = min(
|
||||||
|
i
|
||||||
|
for i in range(1, len(containers) + 1)
|
||||||
|
if any(
|
||||||
|
sum(combination) == TOTAL_EGGNOG
|
||||||
|
for combination in itertools.combinations(containers, i)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return sum(
|
||||||
|
sum(combination) == TOTAL_EGGNOG
|
||||||
|
for combination in itertools.combinations(containers, min_containers)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input = sys.stdin.read()
|
||||||
|
print(solve(input))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue