From f0032ec222d87bfabfd7d863768db98c45a3cda7 Mon Sep 17 00:00:00 2001 From: FaultyBranches Date: Wed, 3 Dec 2025 12:41:06 -0600 Subject: [PATCH] feat: '25 Day 3 --- 25/3/main.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 25/3/test_main.py | 25 ++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 25/3/main.py create mode 100644 25/3/test_main.py diff --git a/25/3/main.py b/25/3/main.py new file mode 100644 index 0000000..6f2a777 --- /dev/null +++ b/25/3/main.py @@ -0,0 +1,60 @@ +# from itertools import combinations + +def get_highest(input: str) -> int: + highest = 0 + + for index, num in enumerate(input): + for subindex, subnum in enumerate(input): + if subindex > index: + highest = max(highest, int(num + subnum)) + + return highest + + +def get_highest_dynamic(bank_size: int, input: str) -> int: + # highest = 0 + + # Brute and "works", but is too expensive + # combos = combinations(input, 12) + + # for c in combos: + # highest = max(highest, int(''.join(c))) + + highest = '' + curr_index = 0 + + for i in range(bank_size, 0, -1): + curr_highest = 0 + highest_index = 0 + limit = len(input) - i + 1 + + for j in range(curr_index, limit): + found = int(input[j]) + + if found > curr_highest: + curr_highest = found + highest_index = j + + highest += str(curr_highest) + curr_index = highest_index + 1 + + return int(highest) + + +def main(): + '''Entrypoint''' + with open('input.txt', encoding='utf-8') as fh: + sum = 0 + sum2 = 0 + + for line in fh: + # sum += get_highest(line) # Old style + sum += get_highest_dynamic(2, line.strip()) + sum2 += get_highest_dynamic(12, line.strip()) + + print(f'Part 1: {sum}') + print(f'Part 2: {sum2}') + + +if __name__ == "__main__": + main() diff --git a/25/3/test_main.py b/25/3/test_main.py new file mode 100644 index 0000000..a493e62 --- /dev/null +++ b/25/3/test_main.py @@ -0,0 +1,25 @@ +import pytest + +from main import get_highest, get_highest_dynamic + +@pytest.mark.parametrize('given, expected', + [ + ('987654321111111', 98), + ('811111111111119', 89), + ('234234234234278', 78), + ('818181911112111', 92) + ]) +def test_get_highest(given, expected): + assert get_highest(given) == expected + + +@pytest.mark.parametrize('given, expected', + [ + ('987654321111111', 987654321111), + ('811111111111119', 811111111119), + ('234234234234278', 434234234278), + ('818181911112111', 888911112111), + ('4123535244222342322334342233754335452333242522124322242423331132232242422443224231234323332243364522', 755554464522) + ]) +def test_get_even_highester(given, expected): + assert get_highest_dynamic(12, given) == expected