Finally done day 24
[advent-of-code-19.git] / problems / day06.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 6 - 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"/>
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 a massive company, and I can
23 only take 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; 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!
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="/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">12*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=</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>
91
92 <div id="sidebar">
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://xebia.com/community/advent-of-code" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Xebia</a> - an international network of passionate technologists and craftspeople, dedicated to exploring and creating new frontiers in IT</div></div>
94 </div><!--/sidebar-->
95
96 <main>
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 6: Universal Orbit Map ---</h2><p>You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input).</p>
99 <p>Except for the universal Center of Mass (<code>COM</code>), every object in space is in orbit around <span title="What do you mean, Kerbal Space Program doesn't have accurate orbital physics?">exactly one other object</span>. An <a href="https://en.wikipedia.org/wiki/Orbit">orbit</a> looks roughly like this:</p>
100 <pre><code> \
101 \
102 |
103 |
104 AAA--&gt; o o &lt;--BBB
105 |
106 |
107 /
108 /
109 </code></pre>
110 <p>In this diagram, the object <code>BBB</code> is in orbit around <code>AAA</code>. The path that <code>BBB</code> takes around <code>AAA</code> (drawn with lines) is only partly shown. In the map data, this orbital relationship is written <code>AAA)BBB</code>, which means "<code>BBB</code> is in orbit around <code>AAA</code>".</p>
111 <p>Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the download. To verify maps, the Universal Orbit Map facility uses <em>orbit count checksums</em> - the total number of <em>direct orbits</em> (like the one shown above) and <em>indirect orbits</em>.</p>
112 <p>Whenever <code>A</code> orbits <code>B</code> and <code>B</code> orbits <code>C</code>, then <code>A</code> <em>indirectly orbits</em> <code>C</code>. This chain can be any number of objects long: if <code>A</code> orbits <code>B</code>, <code>B</code> orbits <code>C</code>, and <code>C</code> orbits <code>D</code>, then <code>A</code> indirectly orbits <code>D</code>.
113 <p>For example, suppose you have the following map:</p>
114 <pre><code>COM)B
115 B)C
116 C)D
117 D)E
118 E)F
119 B)G
120 G)H
121 D)I
122 E)J
123 J)K
124 K)L
125 </code></pre>
126 <p>Visually, the above map of orbits looks like this:</p>
127 <pre><code> G - H J - K - L
128 / /
129 COM - B - C - D - E - F
130 \
131 I
132 </code></pre>
133 <p>In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left.</p>
134 <p>Here, we can count the total number of orbits as follows:</p>
135 <ul>
136 <li><code>D</code> directly orbits <code>C</code> and indirectly orbits <code>B</code> and <code>COM</code>, a total of <code>3</code> orbits.</li>
137 <li><code>L</code> directly orbits <code>K</code> and indirectly orbits <code>J</code>, <code>E</code>, <code>D</code>, <code>C</code>, <code>B</code>, and <code>COM</code>, a total of <code>7</code> orbits.</li>
138 <li><code>COM</code> orbits nothing.</li>
139 </ul>
140 <p>The total number of direct and indirect orbits in this example is <code><em>42</em></code>.</p>
141 <p><em>What is the total number of direct and indirect orbits</em> in your map data?</p>
142 </article>
143 <p>Your puzzle answer was <code>314247</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Now, you just need to figure out how many <em>orbital transfers</em> you (<code>YOU</code>) need to take to get to Santa (<code>SAN</code>).</p>
144 <p>You start at the object <code>YOU</code> are orbiting; your destination is the object <code>SAN</code> is orbiting. An orbital transfer lets you move from any object to an object orbiting or orbited by that object.</p>
145 <p>For example, suppose you have the following map:</p>
146 <pre><code>COM)B
147 B)C
148 C)D
149 D)E
150 E)F
151 B)G
152 G)H
153 D)I
154 E)J
155 J)K
156 K)L
157 K)YOU
158 I)SAN
159 </code></pre>
160 <p>Visually, the above map of orbits looks like this:</p>
161 <pre><code> <em>YOU</em>
162 <em>/</em>
163 G - H <em>J - K</em> - L
164 / <em>/</em>
165 COM - B - C - <em>D - E</em> - F
166 <em>\</em>
167 <em>I - SAN</em>
168 </code></pre>
169 <p>In this example, <code>YOU</code> are in orbit around <code>K</code>, and <code>SAN</code> is in orbit around <code>I</code>. To move from <code>K</code> to <code>I</code>, a minimum of <code>4</code> orbital transfers are required:</p>
170 <ul>
171 <li><code>K</code> to <code>J</code></li>
172 <li><code>J</code> to <code>E</code></li>
173 <li><code>E</code> to <code>D</code></li>
174 <li><code>D</code> to <code>I</code></li>
175 </ul>
176 <p>Afterward, the map of orbits looks like this:</p>
177 <pre><code> G - H J - K - L
178 / /
179 COM - B - C - D - E - F
180 \
181 I - SAN
182 <em>\</em>
183 <em>YOU</em>
184 </code></pre>
185 <p><em>What is the minimum number of orbital transfers required</em> to move from the object <code>YOU</code> are orbiting to the object <code>SAN</code> is orbiting? (Between the objects they are orbiting - <em>not</em> between <code>YOU</code> and <code>SAN</code>.)</p>
186 </article>
187 <p>Your puzzle answer was <code>514</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
188 <p>At this point, you should <a href="/2019">return to your Advent calendar</a> and try another puzzle.</p>
189 <p>If you still want to see it, you can <a href="6/input" target="_blank">get your puzzle input</a>.</p>
190 <p>You can also <span class="share">[Share<span class="share-content">on
191 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Universal+Orbit+Map%22+%2D+Day+6+%2D+Advent+of+Code+2019&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F6&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
192 <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+%22Universal+Orbit+Map%22+%2D+Day+6+%2D+Advent+of+Code+2019+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F6'}else{return false;}" target="_blank">Mastodon</a
193 ></span>]</span> this puzzle.</p>
194 </main>
195
196 <!-- ga -->
197 <script>
198 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
199 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
200 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
201 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
202 ga('create', 'UA-69522494-1', 'auto');
203 ga('set', 'anonymizeIp', true);
204 ga('send', 'pageview');
205 </script>
206 <!-- /ga -->
207 </body>
208 </html>