generated from public/aoc_template
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
import math
|
|
|
|
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(1227775554, "input2_test"),
|
|
(23039913998, "input2"),
|
|
],
|
|
[
|
|
(4174379265, "input2_test"),
|
|
(35950619148, "input2"),
|
|
]
|
|
]
|
|
|
|
def parse_input(self) -> list[tuple[int, ...]]:
|
|
return [tuple(map(int, pair.split("-"))) for pair in self.getInput().split(",")]
|
|
|
|
def part1(self) -> Any:
|
|
ans = 0
|
|
for low, high in self.parse_input():
|
|
for _id in range(low, high + 1):
|
|
str_id = str(_id)
|
|
if str_id[:len(str_id) // 2] == str_id[len(str_id) // 2:]:
|
|
ans += _id
|
|
|
|
return ans
|
|
|
|
def part2(self) -> Any:
|
|
ans = 0
|
|
for low, high in self.parse_input():
|
|
for _id in range(low, high + 1):
|
|
str_id = str(_id)
|
|
for x in range(1, len(str_id) // 2 + 1):
|
|
blocks = set(str_id[i:i+x] for i in range(0, len(str_id), x))
|
|
if len(blocks) == 1:
|
|
ans += _id
|
|
break
|
|
|
|
return ans
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2025, 2)
|
|
day.run(verbose=True)
|