2015: d17: ex1: add solution
This commit is contained in:
parent
89caeed157
commit
a6a126cc3d
1 changed files with 28 additions and 0 deletions
28
2015/d17/ex1/ex1.py
Executable file
28
2015/d17/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/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)
|
||||||
|
return sum(
|
||||||
|
sum(combination) == TOTAL_EGGNOG
|
||||||
|
for combination in itertools.chain.from_iterable(
|
||||||
|
itertools.combinations(containers, i) for i in range(1, len(containers) + 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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