From 6907bff638ab04971e36f1e934080c4c07d3e824 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 18 Jun 2023 23:23:18 +0200 Subject: [PATCH] d2 --- 2015/d2/main.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/2015/d2/main.py b/2015/d2/main.py index a738bb1..5b18ddc 100644 --- a/2015/d2/main.py +++ b/2015/d2/main.py @@ -1,4 +1,5 @@ import re +import math def get_dimentions(inp: str) -> tuple: 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: 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: - presents = map(get_dimentions, map(str.strip, f.readlines())) - wrap_for_each = map(get_wrap, presents) - print(sum(wrap_for_each)) +def get_rubon_present(inp: tuple) -> int: + sides = list(inp) + sides.remove(max(inp)) + 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))