adventofcode/2015/d2/main.py

26 lines
860 B
Python
Raw Normal View History

2023-06-16 19:21:56 +02:00
import re
2023-06-18 23:23:18 +02:00
import math
2023-06-16 19:21:56 +02:00
def get_dimentions(inp: str) -> tuple:
result = re.match("(\d+)x(\d+)x(\d+)",inp)
return tuple(map(int, result.groups()))
def get_wrap(inp: tuple) -> int:
return 2 * inp[0] * inp[1] + 2 * inp[1] * inp[2] + 2 * inp[2] * inp[0] + min(inp[0] * inp[1], inp[1] * inp[2], inp[2] * inp[0])
2023-06-18 23:23:18 +02:00
def get_rubon_present(inp: tuple) -> int:
sides = list(inp)
sides.remove(max(inp))
return (sides[0] + sides[1]) * 2
def get_rubon_bow(inp: tuple) -> int:
return math.prod(inp)
2023-06-16 19:21:56 +02:00
with open("input", "r") as f:
2023-06-18 23:23:18 +02:00
presents = list(map(get_dimentions, map(str.strip, f.readlines())))
wrap_for_each = list(map(get_wrap, presents))
rubon_for_each = list(map(lambda e: get_rubon_present(e) + get_rubon_bow(e), presents))
2023-06-16 19:21:56 +02:00
2023-06-18 23:23:18 +02:00
print("necessary wrap: " ,sum(wrap_for_each))
print("necessary rubbon", sum(rubon_for_each))