(update) new aoc
This commit is contained in:
26
2025/02/main.py
Normal file
26
2025/02/main.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/bin/env python3
|
||||
|
||||
with open("input", "+r") as file:
|
||||
line = file.readline()
|
||||
ranges = line.split(",")
|
||||
invalid = 0
|
||||
INVALID_NUMBERS = []
|
||||
for values in ranges:
|
||||
low = int(values.split("-")[0])
|
||||
high = int(values.split("-")[1])
|
||||
for i in range(low, high + 1):
|
||||
to_string = str(i)
|
||||
split_max = int(to_string.__len__() / 2)
|
||||
for split_at in range(1, split_max + 1):
|
||||
if i in INVALID_NUMBERS:
|
||||
continue
|
||||
left = to_string[:split_at]
|
||||
has_to_have: float = to_string.__len__() / split_at
|
||||
if not has_to_have.is_integer():
|
||||
continue
|
||||
if to_string.count(left) == has_to_have:
|
||||
INVALID_NUMBERS.append(i)
|
||||
invalid = invalid + i
|
||||
print(f"{i} is invalid.")
|
||||
print(INVALID_NUMBERS)
|
||||
print("result", invalid)
|
||||
Reference in New Issue
Block a user