-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday20.html
93 lines (84 loc) · 7.07 KB
/
day20.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
90
91
92
93
<html lang="en-us">
<head>
<meta charset="utf-8" />
<title>Advent of Code 2017</title>
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="./assets/style.css" />
<link rel="shortcut icon" href="./assets/favicon.png" />
<script async src="./assets/header.js"></script>
</head>
<body>
<header>
<div>
<h1 class="title-global"><a href="https://adventofcode.com/2017" target="_blank">Advent of Code</a></h1>
<div class="user">John Dugan <span class="star-count"></span></div>
</div>
<div>
<h1 class="title-event"> <span class="title-event-wrap">{year=></span><a href="https://adventofcode.com/2017" target="_blank">2017</a><span class="title-event-wrap">}</span></h1>
<nav>
<ul>
<li><a href="index.html">[Calendar]</a></li>
<li><a href="https://adventofcode.com/2017/leaderboard/private/view/453227" target="_blank">[Aidn]</a></li>
<li><a href="https://adventofcode.com/2017/leaderboard/private/view/251766" target="_blank">[Memphis]</a></li>
<li><a href="https://adventofcode.com/2017/leaderboard/self" target="_blank">[Personal Stats]</a></li>
</ul>
</nav>
</div>
</header>
<main>
<article class="day-desc">
<h2>--- Day 20: Particle Swarm ---</h2>
<p>Suddenly, the GPU contacts you, asking for <span title="...as if millions of graphics pipelines suddenly cried out for help, but suddenly started working on something else instead because they all have to do the same thing at the same time and can't spend very long asking for help.">help</span>. Someone has asked it to simulate <em>too many particles</em>, and it won't be able to finish them all in time to render the next frame at this rate.</p>
<p>It transmits to you a buffer (your puzzle input) listing each particle in order (starting with particle <code>0</code>, then particle <code>1</code>, particle <code>2</code>, and so on). For each particle, it provides the <code>X</code>, <code>Y</code>, and <code>Z</code> coordinates for the particle's position (<code>p</code>), velocity (<code>v</code>), and acceleration (<code>a</code>), each in the format <code><X,Y,Z></code>.</p>
<p>Each tick, all particles are updated simultaneously. A particle's properties are updated in the following order:</p>
<ul>
<li>Increase the <code>X</code> velocity by the <code>X</code> acceleration.</li>
<li>Increase the <code>Y</code> velocity by the <code>Y</code> acceleration.</li>
<li>Increase the <code>Z</code> velocity by the <code>Z</code> acceleration.</li>
<li>Increase the <code>X</code> position by the <code>X</code> velocity.</li>
<li>Increase the <code>Y</code> position by the <code>Y</code> velocity.</li>
<li>Increase the <code>Z</code> position by the <code>Z</code> velocity.</li>
</ul>
<p>Because of seemingly tenuous rationale involving <a href="https://en.wikipedia.org/wiki/Z-buffering">z-buffering</a>, the GPU would like to know which particle will stay closest to position <code><0,0,0></code> in the long term. Measure this using the <a href="https://en.wikipedia.org/wiki/Taxicab_geometry">Manhattan distance</a>, which in this situation is simply the sum of the absolute values of a particle's <code>X</code>, <code>Y</code>, and <code>Z</code> position.</p>
<p>For example, suppose you are only given two particles, both of which stay entirely on the X-axis (for simplicity). Drawing the current states of particles <code>0</code> and <code>1</code> (in that order) with an adjacent a number line and diagram of current <code>X</code> positions (marked in parentheses), the following would take place:</p>
<pre><code>p=< 3,0,0>, v=< 2,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
p=< 4,0,0>, v=< 0,0,0>, a=<-2,0,0> (0)(1)
p=< 4,0,0>, v=< 1,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
p=< 2,0,0>, v=<-2,0,0>, a=<-2,0,0> (1) (0)
p=< 4,0,0>, v=< 0,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
p=<-2,0,0>, v=<-4,0,0>, a=<-2,0,0> (1) (0)
p=< 3,0,0>, v=<-1,0,0>, a=<-1,0,0> -4 -3 -2 -1 0 1 2 3 4
p=<-8,0,0>, v=<-6,0,0>, a=<-2,0,0> (0) </code></pre>
<p>At this point, particle <code>1</code> will never be closer to <code><0,0,0></code> than particle <code>0</code>, and so, in the long run, particle <code>0</code> will stay closest.</p>
<p><em>Which particle will stay closest to position <code><0,0,0></code></em> in the long term?</p>
</article>
<p>Your puzzle answer was <code>300</code>.</p>
<article class="day-desc">
<h2 id="part2">--- Part Two ---</h2>
<p>To simplify the problem further, the GPU would like to remove any particles that <em>collide</em>. Particles collide if their positions ever <em>exactly match</em>. Because particles are updated simultaneously, <em>more than two particles</em> can collide at the same time and place. Once particles collide, they are removed and cannot collide with anything else after that tick.</p>
<p>For example:</p>
<pre><code>p=<-6,0,0>, v=< 3,0,0>, a=< 0,0,0>
p=<-4,0,0>, v=< 2,0,0>, a=< 0,0,0> -6 -5 -4 -3 -2 -1 0 1 2 3
p=<-2,0,0>, v=< 1,0,0>, a=< 0,0,0> (0) (1) (2) (3)
p=< 3,0,0>, v=<-1,0,0>, a=< 0,0,0>
p=<-3,0,0>, v=< 3,0,0>, a=< 0,0,0>
p=<-2,0,0>, v=< 2,0,0>, a=< 0,0,0> -6 -5 -4 -3 -2 -1 0 1 2 3
p=<-1,0,0>, v=< 1,0,0>, a=< 0,0,0> (0)(1)(2) (3)
p=< 2,0,0>, v=<-1,0,0>, a=< 0,0,0>
p=< 0,0,0>, v=< 3,0,0>, a=< 0,0,0>
p=< 0,0,0>, v=< 2,0,0>, a=< 0,0,0> -6 -5 -4 -3 -2 -1 0 1 2 3
p=< 0,0,0>, v=< 1,0,0>, a=< 0,0,0> X (3)
p=< 1,0,0>, v=<-1,0,0>, a=< 0,0,0>
------destroyed by collision------
------destroyed by collision------ -6 -5 -4 -3 -2 -1 0 1 2 3
------destroyed by collision------ (3)
p=< 0,0,0>, v=<-1,0,0>, a=< 0,0,0></code></pre>
<p>In this example, particles <code>0</code>, <code>1</code>, and <code>2</code> are simultaneously destroyed at the time and place marked <code>X</code>. On the next tick, particle <code>3</code> passes through unharmed.</p>
<p><em>How many particles are left</em> after all collisions are resolved?</p>
</article>
<p>Your puzzle answer was <code>502</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
<p>At this point, all that is left is for you to <a href="index.html">admire your Advent calendar</a>.</p>
<p>If you still want to see it, you can <a href="../data/day20/input.txt" target="_blank">get your puzzle input</a>.</p>
</main>
</body>
</html>