32 lines
771 B
Python
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))
|