2025 - Day 2 part 1

This commit is contained in:
kleph 2025-12-02 18:15:41 +01:00
parent 0ac8fa9f18
commit 000faf832b
3 changed files with 34 additions and 0 deletions

32
2025/2/2.py Normal file
View file

@ -0,0 +1,32 @@
#!/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))

1
2025/2/input.txt Normal file
View file

@ -0,0 +1 @@
245284-286195,797927-983972,4949410945-4949555758,115-282,8266093206-8266228431,1-21,483873-655838,419252-466133,6190-13590,3876510-4037577,9946738680-9946889090,99954692-100029290,2398820-2469257,142130432-142157371,9797879567-9798085531,209853-240025,85618-110471,35694994-35766376,4395291-4476150,33658388-33694159,680915-772910,4973452995-4973630970,52-104,984439-1009605,19489345-19604283,22-42,154149-204168,7651663-7807184,287903-402052,2244-5558,587557762-587611332,307-1038,16266-85176,422394377-422468141

1
2025/2/input_example.txt Normal file
View file

@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124