4 <meta charset=
"utf-8"/>
5 <title>Day
15 - Advent of Code
2017</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?12"/>
9 <link rel=
"stylesheet alternate" type=
"text/css" href=
"/static/highcontrast.css?0" title=
"High Contrast"/>
10 <link rel=
"shortcut icon" href=
"/favicon.ico?2"/>
16 Oh, hello! Funny seeing you here.
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.
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.
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
30 The puzzles probably took the longest; the easiest ones took an hour or two
31 each, but the harder ones took 4-5 hours, and a few even longer than that. A
32 lot of effort went into building this thing - I hope you're enjoying playing it
33 as much as I enjoyed making it for you!
35 If you'd like to hang out, I'm @ericwastl on Twitter.
90 <header><div><h1 class=
"title-global"><a href=
"/">Advent of Code
</a></h1><nav><ul><li><a href=
"/2017/about">[About]
</a></li><li><a href=
"/2017/support">[AoC++]
</a></li><li><a href=
"/2017/events">[Events]
</a></li><li><a href=
"/2017/settings">[Settings]
</a></li><li><a href=
"/2017/auth/logout">[Log Out]
</a></li></ul></nav><div class=
"user">Neil Smith
<span class=
"supporter">(AoC++)
</span> <span class=
"star-count">30*
</span></div></div><div><h1 class=
"title-event"> <span class=
"title-event-wrap">0xffff&</span><a href=
"/2017">2017</a><span class=
"title-event-wrap"></span></h1><nav><ul><li><a href=
"/2017">[Calendar]
</a></li><li><a href=
"/2017/leaderboard">[Leaderboard]
</a></li><li><a href=
"/2017/stats">[Stats]
</a></li><li><a href=
"/2017/sponsors">[Sponsors]
</a></li></ul></nav></div></header>
93 <div id=
"sponsor"><div class=
"quiet">Our
<a href=
"/2017/sponsors">sponsors
</a> help make Advent of Code possible:
</div><p><a href=
"https://formlabs.com/" target=
"_blank" onclick=
"if(ga)ga('send','event','sponsor','click',this.href);" rel=
"noopener">Formlabs
</a> - We make powerful, affordable
3D printers for professionals.
</p></div>
95 <script async
src=
"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
96 <!-- Advent of Code Wide Skyscraper -->
97 <ins class=
"adsbygoogle"
98 style=
"display:inline-block;width:160px;height:600px"
99 data-ad-client=
"ca-pub-9420604735624631"
100 data-ad-slot=
"8014013294"></ins>
102 (adsbygoogle = window.adsbygoogle || []).push({});
105 </div><!--/sidebar-->
108 <article class=
"day-desc"><h2>--- Day
15: Dueling Generators ---
</h2><p>Here, you encounter a pair of dueling
<span title=
"I guess they *are* a little banjo-shaped. Why do you ask?">generators
</span>. The generators, called
<em>generator A
</em> and
<em>generator B
</em>, are trying to agree on a sequence of numbers. However, one of them is malfunctioning, and so the sequences don't always match.
</p>
109 <p>As they do this, a
<em>judge
</em> waits for each of them to generate its next value, compares the lowest
16 bits of both values, and keeps track of the number of times those parts of the values match.
</p>
110 <p>The generators both work on the same principle. To create its next value, a generator will take the previous value it produced, multiply it by a
<em>factor
</em> (generator A uses
<code>16807</code>; generator B uses
<code>48271</code>), and then keep the remainder of dividing that resulting product by
<code>2147483647</code>. That final remainder is the value it produces next.
</p>
111 <p>To calculate each generator's first value, it instead uses a specific starting value as its
"previous value" (as listed in your puzzle input).
</p>
112 <p>For example, suppose that for starting values, generator A uses
<code>65</code>, while generator B uses
<code>8921</code>. Then, the first five pairs of generated values are:
</p>
113 <pre><code>--Gen. A-- --Gen. B--
115 1181022009 1233683848
120 <p>In binary, these pairs are (with generator A's value first in each pair):
</p>
121 <pre><code>00000000000100001010101101100111
122 00011001101010101101001100110111
124 01000110011001001111011100111001
125 01001001100010001000010110001000
127 00001110101000101110001101001010
128 01010101010100101110001101001010
130 01100111111110000001011011000111
131 00001000001101111100110000000111
133 01010000100111111001100000100100
134 00010001000000000010100000000100
136 <p>Here, you can see that the lowest (here, rightmost)
16 bits of the third value match:
<code>1110001101001010</code>. Because of this one match, after processing these five pairs, the judge would have added only
<code>1</code> to its total.
</p>
137 <p>To get a significant sample, the judge would like to consider
<em>40 million
</em> pairs. (In the example above, the judge would eventually find a total of
<code>588</code> pairs that match in their lowest
16 bits.)
</p>
138 <p>After
40 million pairs,
<em>what is the judge's final count
</em>?
</p>
140 <p>Your puzzle answer was
<code>631</code>.
</p><article class=
"day-desc"><h2>--- Part Two ---
</h2><p>In the interest of trying to align a little better, the generators get more picky about the numbers they actually give to the judge.
</p>
141 <p>They still generate values in the same way, but now they only hand a value to the judge when it meets their
<em>criteria
</em>:
</p>
143 <li>Generator A looks for values that are multiples of
<code><em>4</em></code>.
</li>
144 <li>Generator B looks for values that are multiples of
<code><em>8</em></code>.
</li>
146 <p>Each generator functions completely
<em>independently
</em>: they both go through values entirely on their own, only occasionally handing an acceptable value to the judge, and otherwise working through the same sequence of values as before until they find one.
</p>
147 <p>The judge still waits for each generator to provide it with a value before comparing them (using the same comparison method as before). It keeps track of the order it receives values; the first values from each generator are compared, then the second values from each generator, then the third values, and so on.
</p>
148 <p>Using the example starting values given above, the generators now produce the following first five values each:
</p>
149 <pre><code>--Gen. A-- --Gen. B--
150 1352636452 1233683848
153 1980017072 1616057672
156 <p>These values have the following corresponding binary values:
</p>
157 <pre><code>01010000100111111001100000100100
158 01001001100010001000010110001000
160 01110110101111001011111010110000
161 00110011011010001111010010000000
163 00011111101000111101010001100100
164 01000101001000001110100001111000
166 01110110000001001010100110110000
167 01100000010100110001010101001000
169 00101100001000001001111001011000
170 00011000100100101011101101010000
172 <p>Unfortunately, even though this change makes more bits similar on average, none of these values' lowest
16 bits match. Now, it's not until the
1056th pair that the judge finds the first match:
</p>
173 <pre><code>--Gen. A-- --Gen. B--
176 00111101000001010110000111100000
177 00110101011101010110000111100000
179 <p>This change makes the generators much slower, and the judge is getting impatient; it is now only willing to consider
<em>5 million
</em> pairs. (Using the values from the example above, after five million pairs, the judge would eventually find a total of
<code>309</code> pairs that match in their lowest
16 bits.)
</p>
180 <p>After
5 million pairs, but using this new generator logic,
<em>what is the judge's final count
</em>?
</p>
182 <p>Your puzzle answer was
<code>279</code>.
</p><p class=
"day-success">Both parts of this puzzle are complete! They provide two gold stars: **
</p>
183 <p>At this point, you should
<a href=
"/2017">return to your advent calendar
</a> and try another puzzle.
</p>
184 <p>If you still want to see it, you can
<a href=
"15/input" target=
"_blank">get your puzzle input
</a>.
</p>
185 <p>You can also
<span class=
"share">[Share
<span class=
"share-content">on
186 <a href=
"https://twitter.com/intent/tweet?text=I%27ve+completed+%22Dueling+Generators%22+%2D+Day+15+%2D+Advent+of+Code+2017&url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F15&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
187 <a href=
"https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F15" target=
"_blank">Google+
</a>
188 <a href=
"http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F15&title=I%27ve+completed+%22Dueling+Generators%22+%2D+Day+15+%2D+Advent+of+Code+2017" target=
"_blank">Reddit
</a
189 ></span>]
</span> this puzzle.
</p>
194 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
195 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=
1*new Date();a=s.createElement(o),
196 m=s.getElementsByTagName(o)[
0];a.async=
1;a.src=g;m.parentNode.insertBefore(a,m)
197 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
198 ga('create', 'UA-
69522494-
1', 'auto');
199 ga('send', 'pageview');