import re import math 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]) 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) 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))