From 16ba6ca450153d531373438092abd9c3de8b989c Mon Sep 17 00:00:00 2001 From: kleph Date: Fri, 5 Dec 2025 17:01:14 +0100 Subject: [PATCH] 2025 - Day 3 part 2 --- 2025/3/3_2.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2025/3/3_2.py diff --git a/2025/3/3_2.py b/2025/3/3_2.py new file mode 100644 index 0000000..58c1c81 --- /dev/null +++ b/2025/3/3_2.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# 2025 - Advent Of Code 3 - part 2 + +# file = 'input_example.txt' +file = 'input.txt' + +MAX_DIGIT = 12 + +joltage_sum = 0 +with open(file, encoding="utf-8") as f: + max_num = [0] * MAX_DIGIT + for line in f.readlines(): + pos_max = 0 + for digit in range(0, MAX_DIGIT): + max_num[digit] = 0 + for n in range(pos_max, len(line.strip()) - MAX_DIGIT + digit + 1): + if int(line[n]) > max_num[digit]: + max_num[digit] = int(line[n]) + pos_max = n + pos_max += 1 + + joltage = [str(x) for x in max_num] + print(''.join(joltage)) + + joltage_sum += int(''.join(joltage)) + +print(f'Total Joltage: {joltage_sum}') \ No newline at end of file