diff --git a/2025/2/2_2.py b/2025/2/2_2.py new file mode 100644 index 0000000..20ab84d --- /dev/null +++ b/2025/2/2_2.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# 2025 - Advent Of Code 2 - part2 + +# file = 'input_example.txt' +file = 'input.txt' + +ranges = [] +bad_id = [] +with open(file, encoding="utf-8") as f: + for line in f.readlines(): + for r in line.split(','): + (startr, endr) = r.split('-') + for i in range(int(startr), int(endr)+1): + ranges.append(str(i)) + +print(f"ranges to inspect {len(ranges)}") +# print(ranges) + +for product_id in ranges: + for pivot in range(1, int(len(product_id) / 2) + 1): + bad = True + complete_pattern = 0 + for cursor in range(0, len(product_id)): + if product_id[cursor % pivot] != product_id[cursor]: + bad = False + break + complete_pattern = (cursor + 1) % pivot + + if bad and complete_pattern == 0: + bad_id.append(int(product_id)) + +print(f'bad id: {len(bad_id)}') +print(f'dedup bad id: {len(set(bad_id))}') +print(sum(set(bad_id)))