This commit is contained in:
Debucquoy Anthony 2023-06-18 23:23:18 +02:00
parent b4c1879c1b
commit 6907bff638
Signed by: tonitch
GPG Key ID: A78D6421F083D42E

View File

@ -1,4 +1,5 @@
import re import re
import math
def get_dimentions(inp: str) -> tuple: def get_dimentions(inp: str) -> tuple:
result = re.match("(\d+)x(\d+)x(\d+)",inp) result = re.match("(\d+)x(\d+)x(\d+)",inp)
@ -7,9 +8,18 @@ def get_dimentions(inp: str) -> tuple:
def get_wrap(inp: tuple) -> int: 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]) 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])
with open("input", "r") as f: def get_rubon_present(inp: tuple) -> int:
presents = map(get_dimentions, map(str.strip, f.readlines())) sides = list(inp)
wrap_for_each = map(get_wrap, presents) sides.remove(max(inp))
print(sum(wrap_for_each)) return (sides[0] + sides[1]) * 2
# TODO: Missing part two def get_rubon_bow(inp: tuple) -> int:
return math.prod(inp)
with open("input", "r") as f:
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))
print("necessary wrap: " ,sum(wrap_for_each))
print("necessary rubbon", sum(rubon_for_each))