Function advent_solutions::advent2017::day20::part1
[−]
[src]
pub fn part1(particles: &Vec<Particle>) -> usize
Each tick, all particles are updated simultaneously. A particle's properties are updated in the following order:
- Increase the
Xvelocity by theXacceleration. - Increase the
Yvelocity by theYacceleration. - Increase the
Zvelocity by theZacceleration. - Increase the
Xposition by theXvelocity. - Increase the
Yposition by theYvelocity. - Increase the
Zposition by theZvelocity.
Because of seemingly tenuous rationale involving z-buffering, the GPU
would like to know which particle will stay closest to position
<0,0,0> in the long term. Measure this using the Manhattan distance,
which in this situation is simply the sum of the absolute values of a
particle's X, Y, and Z position.
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 0 and 1 (in that order) with an adjacent a number line
and diagram of current X positions (marked in parenthesis), the
following would take place:
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)
At this point, particle 1 will never be closer to <0,0,0> than
particle 0, and so, in the long run, particle 0 will stay closest.
assert_eq!(part1(&input), 0);
Which particle will stay closest to position <0,0,0> in the long
term?