2025 - Day 2 part 2
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
parent
000faf832b
commit
5ae76a626b
1 changed files with 34 additions and 0 deletions
34
2025/2/2_2.py
Normal file
34
2025/2/2_2.py
Normal file
|
|
@ -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)))
|
||||
Loading…
Reference in a new issue