From 9db86877824a267a2723a4f71c1fe9a0fffbbe5d Mon Sep 17 00:00:00 2001 From: Andres Date: Fri, 6 Dec 2024 20:50:38 +0100 Subject: [PATCH] 2015 day 2 part 1 refactor --- 2015/day-2/part-1.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/2015/day-2/part-1.py b/2015/day-2/part-1.py index 68e2bfb..1461aec 100644 --- a/2015/day-2/part-1.py +++ b/2015/day-2/part-1.py @@ -1,22 +1,14 @@ import os -script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in -rel_path = "./input.txt" -# rel_path = "./test-input.txt" - -abs_file_path = os.path.join(script_dir, rel_path) - -input = open(abs_file_path).read() - +file_path = os.path.join(os.path.dirname(__file__), "./input.txt") +input = open(file_path).read().strip() count = 0 -lines = input.splitlines() -for line in lines: - dimensions = list(map(int, line.split("x"))) - dimensions.sort() - area1 = dimensions[0] * dimensions[1] * 2 - area2 = dimensions[1] * dimensions[2] * 2 - area3 = dimensions[0] * dimensions[2] * 2 - total = area1 + area2 + area3 + int(area1 / 2) - count += total + +for line in input.splitlines(): + [x, y, z] = sorted(map(int, line.split("x"))) + areaX = x * y * 2 + areaY = y * z * 2 + areaZ = x * z * 2 + count += areaX + areaY + areaZ + x * y print(count)