advent-of-code/2017-python/solutions/day_17.py

33 lines
731 B
Python
Raw Normal View History

2021-11-01 16:40:46 +01:00
from solutions import BaseSolution
class Solution(BaseSolution):
2025-05-06 20:14:58 +02:00
input_file = "17.txt"
2021-11-01 16:40:46 +01:00
def __str__(self):
2025-05-06 20:14:58 +02:00
return "Day 17: Spinlock"
2021-11-01 16:40:46 +01:00
def solve(self, puzzle_input):
n = int(puzzle_input)
l = [0]
pos = 0
for i in range(1, 2018):
pos = (pos + n) % i + 1
l.insert(pos, i)
return l[pos + 1 % 2017]
def solve_again(self, puzzle_input):
pos = 0
n = int(puzzle_input)
last_seen = 0
2025-05-06 20:14:58 +02:00
for i in range(1, 5 * 10**7 + 1):
2021-11-01 16:40:46 +01:00
pos = (pos + n) % i + 1
if pos == 1:
last_seen = i
return last_seen
2025-05-06 20:14:58 +02:00
if __name__ == "__main__":
2021-11-01 16:40:46 +01:00
solution = Solution()
solution.show_results()