2015/day02: Complete!
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
3a240d8a9a
commit
c73549fe99
|
@ -0,0 +1 @@
|
|||
*.txt
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import functools, operator
|
||||
|
||||
from typing import TextIO
|
||||
|
||||
|
||||
def part1(dimensions: TextIO) -> int:
|
||||
total = 0
|
||||
|
||||
for line in dimensions:
|
||||
line = line.strip().split("x")
|
||||
line = [int(i) for i in line]
|
||||
|
||||
s_area = [2 * line[0] * line[1], 2 * line[1] * line[2], 2 * line[0] * line[2]]
|
||||
|
||||
total += min(s_area) // 2
|
||||
|
||||
total += sum(s_area)
|
||||
|
||||
return total
|
||||
|
||||
|
||||
def part2(dimensions: TextIO) -> int:
|
||||
total = 0
|
||||
|
||||
for line in dimensions:
|
||||
line = line.strip().split("x")
|
||||
line = [int(i) for i in line]
|
||||
line = sorted(line)
|
||||
|
||||
total += (2 * line[0]) + (2 * line[1])
|
||||
total += functools.reduce(operator.mul, line)
|
||||
|
||||
return total
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
f = open("day02.txt", "r")
|
||||
print(part1(f))
|
||||
f = open("day02.txt", "r")
|
||||
print(part2(f))
|
Loading…
Reference in New Issue