AdventOfCode2015/day2.py
marcus@weifer.de 37aa2d6c83 init
2022-12-14 10:37:36 +01:00

35 lines
771 B
Python

file = "day2.txt"
test = "1x1x10"
def part_one(file):
input = open(file, 'r')
result = 0
for line in input:
linesplit = list(map(int, line.split('x')))
d1 = 2 * linesplit[0] * linesplit[1]
d2 = 2 * linesplit[1] * linesplit[2]
d3 = 2 * linesplit[2] * linesplit[0]
lowest_side = [d1 / 2,d2 / 2,d3 / 2]
result += d1 + d2 + d3 + sorted(lowest_side)[0]
print(f"Part 1: {result}")
def part_two(file):
input = open(file, 'r')
result = 0
for line in input:
l, w, h = line.split('x')
l, w, h = int(l), int(w), int(h)
ribbon = 2 * min(l + w, w + h, h + l)
bow = l * w * h
result += ribbon + bow
print(f"Part 2: {result}")
part_one(file)
part_two(file)