4 <meta charset=
"utf-8"/>
5 <title>Day
10 - Advent of Code
2019</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?24"/>
9 <link rel=
"stylesheet alternate" type=
"text/css" href=
"/static/highcontrast.css?0" title=
"High Contrast"/>
10 <link rel=
"shortcut icon" href=
"/favicon.png"/>
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 a massive company, and I can
23 only take 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 are most of the work; preparing a new calendar and a new set of
31 puzzles each year takes all of my free time for 4-5 months. 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!
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=
"/2019/about">[About]
</a></li><li><a href=
"/2019/events">[Events]
</a></li><li><a href=
"https://teespring.com/adventofcode-2019" target=
"_blank">[Shop]
</a></li><li><a href=
"/2019/settings">[Settings]
</a></li><li><a href=
"/2019/auth/logout">[Log Out]
</a></li></ul></nav><div class=
"user">Neil Smith
<a href=
"/2019/support" class=
"supporter-badge" title=
"Advent of Code Supporter">(AoC++)
</a> <span class=
"star-count">20*
</span></div></div><div><h1 class=
"title-event"> <span class=
"title-event-wrap">0x0000|
</span><a href=
"/2019">2019</a><span class=
"title-event-wrap"></span></h1><nav><ul><li><a href=
"/2019">[Calendar]
</a></li><li><a href=
"/2019/support">[AoC++]
</a></li><li><a href=
"/2019/sponsors">[Sponsors]
</a></li><li><a href=
"/2019/leaderboard">[Leaderboard]
</a></li><li><a href=
"/2019/stats">[Stats]
</a></li></ul></nav></div></header>
93 <div id=
"sponsor"><div class=
"quiet">Our
<a href=
"/2019/sponsors">sponsors
</a> help make Advent of Code possible:
</div><div class=
"sponsor"><a href=
"https://www.codethink.co.uk/" target=
"_blank" onclick=
"if(ga)ga('send','event','sponsor','sidebar',this.href);" rel=
"noopener">Codethink Ltd.
</a> - Codethink is a software services company, expert in the use of Open Source technologies for systems software engineering.
</div></div>
97 <script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===
3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});
</script>
98 <article class=
"day-desc"><h2>--- Day
10: Monitoring Station ---
</h2><p>You fly into the asteroid belt and reach the Ceres monitoring station. The Elves here have an emergency: they're having trouble tracking all of the asteroids and can't be sure they're safe.
</p>
99 <p>The Elves would like to build a new monitoring station in a nearby area of space; they hand you a map of all of the asteroids in that region (your puzzle input).
</p>
100 <p>The map indicates whether each position is empty (
<code>.
</code>) or contains an asteroid (
<code>#
</code>). The asteroids are much smaller than they appear on the map, and every asteroid is exactly in the center of its marked position. The asteroids can be described with
<code>X,Y
</code> coordinates where
<code>X
</code> is the distance from the left edge and
<code>Y
</code> is the distance from the top edge (so the top-left corner is
<code>0,
0</code> and the position immediately to its right is
<code>1,
0</code>).
</p>
101 <p>Your job is to figure out which asteroid would be the best place to build a
<em>new monitoring station
</em>. A monitoring station can
<em>detect
</em> any asteroid to which it has
<em>direct line of sight
</em> - that is, there cannot be another asteroid
<em>exactly
</em> between them. This line of sight can be at any angle, not just lines aligned to the grid or
<span title=
"The Elves on Ceres are clearly not concerned with honor.">diagonally
</span>. The
<em>best
</em> location is the asteroid that can
<em>detect
</em> the largest number of other asteroids.
</p>
102 <p>For example, consider the following map:
</p>
109 <p>The best location for a new monitoring station on this map is the highlighted asteroid at
<code>3,
4</code> because it can detect
<code>8</code> asteroids, more than any other location. (The only asteroid it cannot detect is the one at
<code>1,
0</code>; its view of this asteroid is blocked by the asteroid at
<code>2,
2</code>.) All other asteroids are worse locations; they can detect
<code>7</code> or fewer other asteroids. Here is the number of other asteroids a monitoring station on each asteroid could detect:
</p>
116 <p>Here is an asteroid (
<code>#
</code>) and some examples of the ways its line of sight might be blocked. If there were another asteroid at the location of a capital letter, the locations marked with the corresponding lowercase letter would be blocked and could not be detected:
</p>
117 <pre><code>#.........
128 <p>Here are some larger examples:
</p>
130 <li><p>Best is
<code>5,
8</code> with
<code>33</code> other asteroids detected:
</p>
131 <pre><code>......#.#.
142 <li><p>Best is
<code>1,
2</code> with
<code>35</code> other asteroids detected:
</p>
143 <pre><code>#.#...#.#.
154 <li><p>Best is
<code>6,
3</code> with
<code>41</code> other asteroids detected:
</p>
155 <pre><code>.#..#..###
166 <li><p>Best is
<code>11,
13</code> with
<code>210</code> other asteroids detected:
</p>
167 <pre><code>.#..##.###...#######
180 ##...#.####
<em>#
</em>#####...
189 <p>Find the best location for a new monitoring station.
<em>How many other asteroids can be detected from that location?
</em></p>
191 <p>Your puzzle answer was
<code>221</code>.
</p><article class=
"day-desc"><h2 id=
"part2">--- Part Two ---
</h2><p>Once you give them the coordinates, the Elves quickly deploy an Instant Monitoring Station to the location and discover
<span title=
"The Elves on Ceres just have a unique system of values, that's all.">the worst
</span>: there are simply too many asteroids.
</p>
192 <p>The only solution is
<em>complete vaporization by giant laser
</em>.
</p>
193 <p>Fortunately, in addition to an asteroid scanner, the new monitoring station also comes equipped with a giant rotating laser perfect for vaporizing asteroids. The laser starts by pointing
<em>up
</em> and always rotates
<em>clockwise
</em>, vaporizing any asteroid it hits.
</p>
194 <p>If multiple asteroids are
<em>exactly
</em> in line with the station, the laser only has enough power to vaporize
<em>one
</em> of them before continuing its rotation. In other words, the same asteroids that can be
<em>detected
</em> can be vaporized, but if vaporizing one asteroid makes another one detectable, the newly-detected asteroid won't be vaporized until the laser has returned to the same position by rotating a full
360 degrees.
</p>
195 <p>For example, consider the following map, where the asteroid with the new monitoring station (and laser) is marked
<code>X
</code>:
</p>
196 <pre><code>.#....#####...#..
202 <p>The first nine asteroids to get vaporized, in order, would be:
</p>
203 <pre><code>.#....###
<em>2</em><em>4</em>...#..
204 ##...##.
<em>1</em><em>3</em>#
<em>6</em><em>7</em>..
<em>9</em>#
205 ##...#...
<em>5</em>.
<em>8</em>####.
209 <p>Note that some asteroids (the ones behind the asteroids marked
<code>1</code>,
<code>5</code>, and
<code>7</code>) won't have a chance to be vaporized until the next full rotation. The laser continues rotating; the next nine to be vaporized are:
</p>
210 <pre><code>.#....###.....#..
212 ##...#......
<em>1</em><em>2</em><em>3</em><em>4</em>.
213 ..#.....X...
<em>5</em>##..
214 ..#.
<em>9</em>.....
<em>8</em>....
<em>7</em><em>6</em>
216 <p>The next nine to be vaporized are then:
</p>
217 <pre><code>.
<em>8</em>....###.....#..
218 <em>5</em><em>6</em>...
<em>9</em>#...#.....#
219 <em>3</em><em>4</em>...
<em>7</em>...........
220 ..
<em>2</em>.....X....##..
221 ..
<em>1</em>..............
223 <p>Finally, the laser completes its first full rotation (
<code>1</code> through
<code>3</code>), a second rotation (
<code>4</code> through
<code>8</code>), and vaporizes the last asteroid (
<code>9</code>) partway through its third rotation:
</p>
224 <pre><code>......
<em>2</em><em>3</em><em>4</em>.....
<em>6</em>..
225 ......
<em>1</em>...
<em>5</em>.....
<em>7</em>
227 ........X....
<em>8</em><em>9</em>..
230 <p>In the large example above (the one with the best monitoring station location at
<code>11,
13</code>):
</p>
232 <li>The
1st asteroid to be vaporized is at
<code>11,
12</code>.
</li>
233 <li>The
2nd asteroid to be vaporized is at
<code>12,
1</code>.
</li>
234 <li>The
3rd asteroid to be vaporized is at
<code>12,
2</code>.
</li>
235 <li>The
10th asteroid to be vaporized is at
<code>12,
8</code>.
</li>
236 <li>The
20th asteroid to be vaporized is at
<code>16,
0</code>.
</li>
237 <li>The
50th asteroid to be vaporized is at
<code>16,
9</code>.
</li>
238 <li>The
100th asteroid to be vaporized is at
<code>10,
16</code>.
</li>
239 <li>The
199th asteroid to be vaporized is at
<code>9,
6</code>.
</li>
240 <li><em>The
200th asteroid to be vaporized is at
<code>8,
2</code>.
</em></li>
241 <li>The
201st asteroid to be vaporized is at
<code>10,
9</code>.
</li>
242 <li>The
299th and final asteroid to be vaporized is at
<code>11,
1</code>.
</li>
244 <p>The Elves are placing bets on which will be the
<em>200th
</em> asteroid to be vaporized. Win the bet by determining which asteroid that will be;
<em>what do you get if you multiply its X coordinate by
<code>100</code> and then add its Y coordinate?
</em> (For example,
<code>8,
2</code> becomes
<em><code>802</code></em>.)
</p>
246 <p>Your puzzle answer was
<code>806</code>.
</p><p class=
"day-success">Both parts of this puzzle are complete! They provide two gold stars: **
</p>
247 <p>At this point, you should
<a href=
"/2019">return to your Advent calendar
</a> and try another puzzle.
</p>
248 <p>If you still want to see it, you can
<a href=
"10/input" target=
"_blank">get your puzzle input
</a>.
</p>
249 <p>You can also
<span class=
"share">[Share
<span class=
"share-content">on
250 <a href=
"https://twitter.com/intent/tweet?text=I%27ve+completed+%22Monitoring+Station%22+%2D+Day+10+%2D+Advent+of+Code+2019&url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F10&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
251 <a href=
"javascript:void(0);" onclick=
"var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Monitoring+Station%22+%2D+Day+10+%2D+Advent+of+Code+2019+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F10'}else{return false;}" target=
"_blank">Mastodon
</a
252 ></span>]
</span> this puzzle.
</p>
257 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
258 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=
1*new Date();a=s.createElement(o),
259 m=s.getElementsByTagName(o)[
0];a.async=
1;a.src=g;m.parentNode.insertBefore(a,m)
260 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
261 ga('create', 'UA-
69522494-
1', 'auto');
262 ga('set', 'anonymizeIp', true);
263 ga('send', 'pageview');