day17
This commit is contained in:
parent
945ab0c86d
commit
9a5897748b
40
day17.py
Normal file
40
day17.py
Normal file
@ -0,0 +1,40 @@
|
||||
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)
|
||||
1
inputs/input17
Normal file
1
inputs/input17
Normal file
@ -0,0 +1 @@
|
||||
359
|
||||
1
inputs/input17_test
Normal file
1
inputs/input17_test
Normal file
@ -0,0 +1 @@
|
||||
3
|
||||
Loading…
Reference in New Issue
Block a user