diff --git a/2025/day06/part2.py b/2025/day06/part2.py new file mode 100644 index 0000000..f3c413c --- /dev/null +++ b/2025/day06/part2.py @@ -0,0 +1,31 @@ +import math + +text: str + +with open("input.txt") as f: + text = f.read() + +total: int = 0 + +def calc(lines: list[str], start: int, stop: int) -> int: + numbers: list[int] = [] + for i in range(start, stop): + number: int = 0 + for line in lines[:-1]: + if (line[i] != ' '): + number = number * 10 + int(line[i]) + numbers.append(number) + operator = lines[-1][start] + if (operator == "+"): + return sum(numbers) + return math.prod(numbers) + +lines: list[str] = text.splitlines() +prev = len(lines[-1]) +for i in range(len(lines[-1]) - 1, -1, -1): + operator: str = lines[-1][i] + if (operator in "+*"): + total += calc(lines, i, prev) + prev = i - 1 + +print(total) \ No newline at end of file