Function advent_solutions::advent2017::day17::part1
[−]
[src]
pub fn part1(input: &usize) -> usize
For example, if the spinlock were to step 3 times per insert, the
circular buffer would begin to evolve like this (using parentheses to
mark the current position after each iteration of the algorithm):
-
(0), the initial state before any insertions. -
0 (1): the spinlock steps forward three times (0,0,0), and then inserts the first value,1, after it.1becomes the current position. -
0 (2) 1: the spinlock steps forward three times (0,1,0), and then inserts the second value,2, after it.2becomes the current position. -
0 2 (3) 1: the spinlock steps forward three times (1,0,2), and then inserts the third value,3, after it.3becomes the current position.
And so on:
-
0 2 (4) 3 1 -
0 (5) 2 4 3 1 -
0 5 2 4 3 (6) 1 -
0 5 (7) 2 4 3 6 1 -
0 5 7 2 4 3 (8) 6 1 -
0 (9) 5 7 2 4 3 8 6 1
Eventually, after 2017 insertions, the section of the circular buffer near the last insertion looks like this:
1512 1134 151 (2017) 638 1513 851
Perhaps, if you can identify the value that will ultimately be after
the last value written (2017), you can short-circuit the spinlock. In
this example, that would be 638.
assert_eq!(part1(&3), 638)
What is the value after 2017 in your completed circular buffer?