aoc2017/day17.py
2022-12-03 10:23:57 +01:00

41 lines
843 B
Python

from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(638, "input17_test"),
(1506, "input17"),
],
[
(39479736, "input17")
]
]
def part1(self) -> Any:
step = self.getInput(int)
buffer = [0]
index = 0
for i in range(2017):
index = (index + step) % len(buffer) + 1
buffer.insert(index, i + 1)
return buffer[buffer.index(2017) + 1]
def part2(self) -> Any:
step = self.getInput(int)
index = 0
ans = 0
for i in range(50_000_000):
index = (index + step) % (i + 1) + 1
if index == 1:
ans = i + 1
return ans
if __name__ == '__main__':
day = Day(2017, 17)
day.run(verbose=True)