add: part2
This commit is contained in:
24
2025/day02/part2.py
Normal file
24
2025/day02/part2.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import math
|
||||||
|
text: str
|
||||||
|
|
||||||
|
with open("input.txt") as f:
|
||||||
|
text = f.read()
|
||||||
|
|
||||||
|
def get_invalid(value_str: str) -> bool:
|
||||||
|
length: int = len(value_str)
|
||||||
|
for i in range(length):
|
||||||
|
repeat: int = value_str.count(value_str[:(i+1)])
|
||||||
|
if (repeat == 1):
|
||||||
|
break
|
||||||
|
if (repeat * (i + 1) == length):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
total: int = 0
|
||||||
|
for start, stop in [line.split("-") for line in text.split(",")]:
|
||||||
|
for value in range(int(start), int(stop) + 1):
|
||||||
|
value_str: str = str(value)
|
||||||
|
if get_invalid(value_str):
|
||||||
|
total += value
|
||||||
|
|
||||||
|
print(total)
|
||||||
Reference in New Issue
Block a user