comparison 2017/day17/problem @ 34:049fb8e56025

Add problem statements and inputs
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 09 Jan 2018 21:51:44 -0500
parents
children
comparison
equal deleted inserted replaced
33:bc652fa0a645 34:049fb8e56025
1 --- Day 17: Spinlock ---
2
3 Suddenly, whirling in the distance, you notice what looks like a
4 massive, pixelated hurricane: a deadly spinlock. This spinlock isn't
5 just consuming computing power, but memory, too; vast, digital
6 mountains are being ripped from the ground and consumed by the vortex.
7
8 If you don't move quickly, fixing that printer will be the least of
9 your problems.
10
11 This spinlock's algorithm is simple but efficient, quickly consuming
12 everything in its path. It starts with a circular buffer containing
13 only the value 0, which it marks as the current position. It then
14 steps forward through the circular buffer some number of steps (your
15 puzzle input) before inserting the first new value, 1, after the value
16 it stopped on. The inserted value becomes the current position. Then,
17 it steps forward from there the same number of steps, and wherever it
18 stops, inserts after it the second new value, 2, and uses that as the
19 new current position again.
20
21 It repeats this process of stepping forward, inserting a new value,
22 and using the location of the inserted value as the new current
23 position a total of 2017 times, inserting 2017 as its final operation,
24 and ending with a total of 2018 values (including 0) in the circular
25 buffer.
26
27 For example, if the spinlock were to step 3 times per insert, the
28 circular buffer would begin to evolve like this (using parentheses to
29 mark the current position after each iteration of the algorithm):
30
31 (0), the initial state before any insertions.
32
33 0 (1): the spinlock steps forward three times (0, 0, 0), and then
34 inserts the first value, 1, after it. 1 becomes the current
35 position.
36
37 0 (2) 1: the spinlock steps forward three times (0, 1, 0), and
38 then inserts the second value, 2, after it. 2 becomes the current
39 position.
40
41 0 2 (3) 1: the spinlock steps forward three times (1, 0, 2), and
42 then inserts the third value, 3, after it. 3 becomes the current
43 position.
44
45
46 And so on:
47
48 0 2 (4) 3 1
49 0 (5) 2 4 3 1
50 0 5 2 4 3 (6) 1
51 0 5 (7) 2 4 3 6 1
52 0 5 7 2 4 3 (8) 6 1
53 0 (9) 5 7 2 4 3 8 6 1
54
55 Eventually, after 2017 insertions, the section of the circular buffer
56 near the last insertion looks like this:
57
58 1512 1134 151 (2017) 638 1513 851
59
60 Perhaps, if you can identify the value that will ultimately be after
61 the last value written (2017), you can short-circuit the spinlock. In
62 this example, that would be 638.
63
64 What is the value after 2017 in your completed circular buffer?
65
66 Your puzzle answer was 1306.
67
68 --- Part Two ---
69
70 The spinlock does not short-circuit. Instead, it gets more angry. At
71 least, you assume that's what happened; it's spinning significantly
72 faster than it was a moment ago.
73
74 You have good news and bad news.
75
76 The good news is that you have improved calculations for how to stop
77 the spinlock. They indicate that you actually need to identify the
78 value after 0 in the current state of the circular buffer.
79
80 The bad news is that while you were determining this, the spinlock has
81 just finished inserting its fifty millionth value (50000000).
82
83 What is the value after 0 the moment 50000000 is inserted?
84
85 Your puzzle answer was 20430489.
86
87 Both parts of this puzzle are complete! They provide two gold stars: **