From 4d49abf0ac1a8d300d45ead9831cf2447d555fd5 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Mon, 12 Jan 2026 14:06:44 -0800 Subject: [PATCH] 2025 06 --- Python/2025/06/main.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Python/2025/06/main.py diff --git a/Python/2025/06/main.py b/Python/2025/06/main.py new file mode 100644 index 0000000..e317148 --- /dev/null +++ b/Python/2025/06/main.py @@ -0,0 +1,51 @@ +input = open("input", 'r').read().rstrip().split("\n") + +problems = input[0].split() +for line in input[1:]: + problems = list(zip(problems,line.split())) + +def evaluate(value,values,op): + if isinstance(values, tuple): + return op(value, evaluate(values[1], values[0], op)) + return op(value, values) + +def part1(problems): + total = [] + for problem in problems: + if problem[1] == "+": + op = lambda x,y: int(x)+int(y) + total.append(evaluate(0, problem[0], op)) + elif problem[1] == "*": + op = lambda x,y: int(x)*int(y) + total.append(evaluate(1, problem[0], op)) + return total + +print(sum(part1(problems))) + +# Part 2 :sob: +text_input = [line for line in input] +corrected_problems = [] +height = len(text_input) + +corrected_problem = None +op_code = None +for col in range(len(text_input[0])): + + if op_code == None: + op_code = text_input[height-1][col] + value = [text_input[i][col] for i in range(height-1)] + if value == [" " for _ in range(height-1)]: + corrected_problems.append((corrected_problem, op_code)) + corrected_problem = None + op_code = None + continue + + if corrected_problem == None: + corrected_problem = int("".join(value)) + else: + corrected_problem = (corrected_problem, int("".join(value))) + +corrected_problems.append((corrected_problem, op_code)) + +print(sum(part1(corrected_problems))) +