generated from public/aoc_template
60 lines
1.3 KiB
Python
60 lines
1.3 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any, Generator
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(3, "input1_test"),
|
|
(1123, "input1_dennis"),
|
|
(997, "input1"),
|
|
],
|
|
[
|
|
(6, "input1_test"),
|
|
(6695, "input1_dennis"),
|
|
(5978, "input1"),
|
|
]
|
|
]
|
|
|
|
def parse_input(self) -> Generator[tuple[Any, int], Any, None]:
|
|
for line in self.getInput():
|
|
yield line[0], int(line[1:])
|
|
|
|
def part1(self) -> Any:
|
|
dial = 50
|
|
ans = 0
|
|
|
|
for rotation, clicks in self.parse_input():
|
|
if rotation == "L":
|
|
dial = (dial - clicks) % 100
|
|
else:
|
|
dial = (dial + clicks) % 100
|
|
|
|
ans += (dial == 0)
|
|
|
|
return ans
|
|
|
|
def part2(self) -> Any:
|
|
dial = 50
|
|
ans = 0
|
|
|
|
for rotation, clicks in self.parse_input():
|
|
ans += clicks // 100
|
|
clicks %= 100
|
|
|
|
if rotation == "L":
|
|
if clicks >= dial and dial != 0:
|
|
ans += 1
|
|
dial = (dial - clicks) % 100
|
|
else:
|
|
if clicks >= 100 - dial and dial != 0:
|
|
ans += 1
|
|
dial = (dial + clicks) % 100
|
|
|
|
return ans
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2025, 1)
|
|
day.run(verbose=True)
|