advent_of_code/2025/2/2.py
2025-12-02 18:18:51 +01:00

32 lines
771 B
Python

#!/usr/bin/env python
# 2025 - Advent Of Code 2
# 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:
if len(product_id) % 2 == 1:
continue
half = int(len(product_id) / 2)
bad = True
for cursor in range(0, half):
if product_id[cursor] != product_id[half + cursor]:
bad = False
break
if bad:
bad_id.append(int(product_id))
# print(bad_id)
print(sum(bad_id))