2015: d02: ex2: add solution
This commit is contained in:
parent
3e12df9ac7
commit
175f1773bd
1 changed files with 28 additions and 0 deletions
28
2015/d02/ex2/ex2.py
Executable file
28
2015/d02/ex2/ex2.py
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def parse_line(input: str) -> tuple[int, int, int]:
|
||||
x, y, z = map(int, input.split("x"))
|
||||
return x, y, z
|
||||
|
||||
def parse(input: str) -> list[tuple[int, int, int]]:
|
||||
return [parse_line(line) for line in input.splitlines()]
|
||||
|
||||
def ribbon(x: int, y: int, z: int) -> int:
|
||||
bow = x * y * z
|
||||
return 2 * min(x + y, y + z, z + x) + bow
|
||||
|
||||
presents = parse(input)
|
||||
return sum(ribbon(*present) for present in presents)
|
||||
|
||||
|
||||
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