add: day02: part1
This commit is contained in:
16
2025/day02/part1.py
Normal file
16
2025/day02/part1.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import math
|
||||||
|
text: str
|
||||||
|
|
||||||
|
with open("input.txt") as f:
|
||||||
|
text = f.read()
|
||||||
|
|
||||||
|
total: int = 0
|
||||||
|
for start, stop in [line.split("-") for line in text.split(",")]:
|
||||||
|
for value in range(int(start), int(stop) + 1):
|
||||||
|
length: int = int(math.log10(value))
|
||||||
|
if length % 2 == 1:
|
||||||
|
value_str: str = str(value)
|
||||||
|
if (value_str[0:length // 2 + 1] == value_str[length // 2 + 1:]):
|
||||||
|
total += value
|
||||||
|
|
||||||
|
print(total)
|
||||||
Reference in New Issue
Block a user