generated from public/aoc_template
day02
This commit is contained in:
parent
82ad1d0dbe
commit
270e9dc482
48
day02.py
Normal file
48
day02.py
Normal file
@ -0,0 +1,48 @@
|
||||
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)
|
||||
1
inputs/input2
Normal file
1
inputs/input2
Normal file
@ -0,0 +1 @@
|
||||
92916254-92945956,5454498003-5454580069,28-45,4615-7998,4747396917-4747534264,272993-389376,36290651-36423050,177-310,3246326-3418616,48-93,894714-949755,952007-1003147,3-16,632-1029,420-581,585519115-585673174,1041-1698,27443-39304,71589003-71823870,97-142,2790995-2837912,579556301-579617006,653443-674678,1515120817-1515176202,13504-20701,1896-3566,8359-13220,51924-98061,505196-638209,67070129-67263432,694648-751703,8892865662-8892912125
|
||||
1
inputs/input2_test
Normal file
1
inputs/input2_test
Normal file
@ -0,0 +1 @@
|
||||
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
|
||||
@ -11,7 +11,7 @@ import webbrowser
|
||||
|
||||
YEAR = 2025
|
||||
CHARMS = {
|
||||
'Linux': '/home/pennywise/bin/pycharm',
|
||||
'Linux': '/home/sharmuth/bin/pycharm',
|
||||
'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd'
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user