2015/day02: Complete!
ci/woodpecker/push/woodpecker Pipeline was successful Details

main
earnest ma 2023-05-08 11:04:37 -04:00
parent 3a240d8a9a
commit c73549fe99
Signed by: earnest ma
GPG Key ID: A343F43342EB6E2A
3 changed files with 43 additions and 1 deletions

1
2015/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.txt

File diff suppressed because one or more lines are too long

42
2015/day02.py Normal file
View File

@ -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))