35 lines
778 B
Python
35 lines
778 B
Python
file = "inputs/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) |