Done day 9
[advent-of-code-18.git] / problems / day09.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 9 - Advent of Code 2018</title>
6 <!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
7 <link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
8 <link rel="stylesheet" type="text/css" href="/static/style.css?18"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.png"/>
11 </head><!--
12
13
14
15
16 Oh, hello! Funny seeing you here.
17
18 I appreciate your enthusiasm, but you aren't going to find much down here.
19 There certainly aren't clues to any of the puzzles. The best surprises don't
20 even appear in the source until you unlock them for real.
21
22 Please be careful with automated requests; I'm not Google, and I can only take
23 so much traffic. Please be considerate so that everyone gets to play.
24
25 If you're curious about how Advent of Code works, it's running on some custom
26 Perl code. Other than a few integrations (auth, analytics, ads, social media),
27 I built the whole thing myself, including the design, animations, prose, and
28 all of the puzzles.
29
30 The puzzles are most of the work; the easiest ones take 3-4 hours each, but the
31 harder ones take 6-8 hours, and a few even longer than that. A lot of effort
32 went into building this thing - I hope you're enjoying playing it as much as I
33 enjoyed making it for you!
34
35 If you'd like to hang out, I'm @ericwastl on Twitter.
36
37 - Eric Wastl
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 -->
89 <body>
90 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2018/about">[About]</a></li><li><a href="/2018/events">[Events]</a></li><li><a href="https://teespring.com/adventofcode" target="_blank">[Shop]</a></li><li><a href="/2018/settings">[Settings]</a></li><li><a href="/2018/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2018/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">18*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">&lt;y&gt;</span><a href="/2018">2018</a><span class="title-event-wrap">&lt;/y&gt;</span></h1><nav><ul><li><a href="/2018">[Calendar]</a></li><li><a href="/2018/support">[AoC++]</a></li><li><a href="/2018/sponsors">[Sponsors]</a></li><li><a href="/2018/leaderboard">[Leaderboard]</a></li><li><a href="/2018/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2018/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://aoc.prodo.ai/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Alfie by Prodo</a> - a more immediate, feedback-driven coding experience. Try our online JavaScript playground with Advent of Code!</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <article class="day-desc"><h2>--- Day 9: Marble Mania ---</h2><p>You talk to the Elves while you wait for your navigation system to <span title="Do you have any idea how long it takes to load navigation data for all of time and space?!">initialize</span>. To pass the time, they introduce you to their favorite <a href="https://en.wikipedia.org/wiki/Marble_(toy)">marble</a> game.</p>
98 <p>The Elves play this game by taking turns arranging the marbles in a <em>circle</em> according to very particular rules. The marbles are numbered starting with <code>0</code> and increasing by <code>1</code> until every marble has a number.</p>
99 <p>First, the marble numbered <code>0</code> is placed in the circle. At this point, while it contains only a single marble, it is still a circle: the marble is both clockwise from itself and counter-clockwise from itself. This marble is designated the <em>current marble</em>.</p>
100 <p>Then, each Elf takes a turn placing the <em>lowest-numbered remaining marble</em> into the circle between the marbles that are <code>1</code> and <code>2</code> marbles <em>clockwise</em> of the current marble. (When the circle is large enough, this means that there is one marble between the marble that was just placed and the current marble.) The marble that was just placed then becomes the <em>current marble</em>.</p>
101 <p>However, if the marble that is about to be placed has a number which is a multiple of <code>23</code>, <em>something entirely different happens</em>. First, the current player keeps the marble they would have placed, adding it to their <em>score</em>. In addition, the marble <code>7</code> marbles <em>counter-clockwise</em> from the current marble is <em>removed</em> from the circle and <em>also</em> added to the current player's score. The marble located immediately <em>clockwise</em> of the marble that was removed becomes the new <em>current marble</em>.</p>
102 <p>For example, suppose there are 9 players. After the marble with value <code>0</code> is placed in the middle, each player (shown in square brackets) takes a turn. The result of each of those turns would produce circles of marbles like this, where clockwise is to the right and the resulting current marble is in parentheses:</p>
103 <pre><code>[-] <em>(0)</em>
104 [1] 0<em> (1)</em>
105 [2] 0<em> (2)</em> 1
106 [3] 0 2 1<em> (3)</em>
107 [4] 0<em> (4)</em> 2 1 3
108 [5] 0 4 2<em> (5)</em> 1 3
109 [6] 0 4 2 5 1<em> (6)</em> 3
110 [7] 0 4 2 5 1 6 3<em> (7)</em>
111 [8] 0<em> (8)</em> 4 2 5 1 6 3 7
112 [9] 0 8 4<em> (9)</em> 2 5 1 6 3 7
113 [1] 0 8 4 9 2<em>(10)</em> 5 1 6 3 7
114 [2] 0 8 4 9 2 10 5<em>(11)</em> 1 6 3 7
115 [3] 0 8 4 9 2 10 5 11 1<em>(12)</em> 6 3 7
116 [4] 0 8 4 9 2 10 5 11 1 12 6<em>(13)</em> 3 7
117 [5] 0 8 4 9 2 10 5 11 1 12 6 13 3<em>(14)</em> 7
118 [6] 0 8 4 9 2 10 5 11 1 12 6 13 3 14 7<em>(15)</em>
119 [7] 0<em>(16)</em> 8 4 9 2 10 5 11 1 12 6 13 3 14 7 15
120 [8] 0 16 8<em>(17)</em> 4 9 2 10 5 11 1 12 6 13 3 14 7 15
121 [9] 0 16 8 17 4<em>(18)</em> 9 2 10 5 11 1 12 6 13 3 14 7 15
122 [1] 0 16 8 17 4 18 9<em>(19)</em> 2 10 5 11 1 12 6 13 3 14 7 15
123 [2] 0 16 8 17 4 18 9 19 2<em>(20)</em>10 5 11 1 12 6 13 3 14 7 15
124 [3] 0 16 8 17 4 18 9 19 2 20 10<em>(21)</em> 5 11 1 12 6 13 3 14 7 15
125 [4] 0 16 8 17 4 18 9 19 2 20 10 21 5<em>(22)</em>11 1 12 6 13 3 14 7 15
126 [5] 0 16 8 17 4 18<em>(19)</em> 2 20 10 21 5 22 11 1 12 6 13 3 14 7 15
127 [6] 0 16 8 17 4 18 19 2<em>(24)</em>20 10 21 5 22 11 1 12 6 13 3 14 7 15
128 [7] 0 16 8 17 4 18 19 2 24 20<em>(25)</em>10 21 5 22 11 1 12 6 13 3 14 7 15
129 </code></pre>
130 <p>The goal is to be the <em>player with the highest score</em> after the last marble is used up. Assuming the example above ends after the marble numbered <code>25</code>, the winning score is <code>23+9=<em>32</em></code> (because player 5 kept marble <code>23</code> and removed marble <code>9</code>, while no other player got any points in this very short example game).</p>
131 <p>Here are a few more examples:</p>
132 <ul>
133 <li><code>10</code> players; last marble is worth <code>1618</code> points: high score is <em><code>8317</code></em></li>
134 <li><code>13</code> players; last marble is worth <code>7999</code> points: high score is <em><code>146373</code></em></li>
135 <li><code>17</code> players; last marble is worth <code>1104</code> points: high score is <em><code>2764</code></em></li>
136 <li><code>21</code> players; last marble is worth <code>6111</code> points: high score is <em><code>54718</code></em></li>
137 <li><code>30</code> players; last marble is worth <code>5807</code> points: high score is <em><code>37305</code></em></li>
138 </ul>
139 <p><em>What is the winning Elf's score?</em></p>
140 </article>
141 <p>Your puzzle answer was <code>398048</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Amused by the speed of your answer, the Elves are curious:</p>
142 <p><em>What would the new winning Elf's score be if the number of the last marble were 100 times larger?</em></p>
143 </article>
144 <p>Your puzzle answer was <code>3180373421</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
145 <p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
146 <p>If you still want to see it, you can <a href="9/input" target="_blank">get your puzzle input</a>.</p>
147 <p>You can also <span class="share">[Share<span class="share-content">on
148 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Marble+Mania%22+%2D+Day+9+%2D+Advent+of+Code+2018&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F9&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
149 <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F9&amp;title=I%27ve+completed+%22Marble+Mania%22+%2D+Day+9+%2D+Advent+of+Code+2018" target="_blank">Reddit</a
150 ></span>]</span> this puzzle.</p>
151 </main>
152
153 <!-- ga -->
154 <script>
155 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
156 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
157 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
158 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
159 ga('create', 'UA-69522494-1', 'auto');
160 ga('send', 'pageview');
161 </script>
162 <!-- /ga -->
163 </body>
164 </html>