aoc/2015/day02.py

43 lines
848 B
Python

#!/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))