[−][src]Function codetrotter_aoc_2019_solutions::day_06::solve_part_2
pub fn solve_part_2<'a, T>(input_orbit_pairs: &mut T) -> usize where
T: Iterator<Item = OrbitPair<'a>>,
Day 6, Part Two
https://adventofcode.com/2019/day/6#part2
Now, you just need to figure out how many orbital transfers you (YOU
) need
to take to get to Santa (SAN
).
You start at the object YOU
are orbiting; your destination is the object
SAN
is orbiting. An orbital transfer lets you move from any object to an
object orbiting or orbited by that object.
For example, suppose you have the following map:
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
K)YOU
I)SAN
Visually, the above map of orbits looks like this:
YOU
/
G - H J - K - L
/ /
COM - B - C - D - E - F
\
I - SAN
In this example, YOU
are in orbit around K
, and SAN
is in orbit around I
.
To move from K
to I
, a minimum of 4
orbital transfers are required:
K
toJ
J
toE
E
toD
D
toI
Afterward, the map of orbits looks like this:
G - H J - K - L
/ /
COM - B - C - D - E - F
\
I - SAN
\
YOU
What is the minimum number of orbital transfers required to move from the
object YOU
are orbiting to the object SAN
is orbiting? (Between the objects
they are orbiting - not between YOU
and SAN
.)
Examples
use codetrotter_aoc_2019_solutions::day_06::{input_generator, solve_part_2}; const EXINPUT: &str = "COM)B\n\ B)C\n\ C)D\n\ D)E\n\ E)F\n\ B)G\n\ G)H\n\ D)I\n\ E)J\n\ J)K\n\ K)L\n\ K)YOU\n\ I)SAN"; assert_eq!(solve_part_2(&mut input_generator(EXINPUT)), 4);
Solution
⚠️ SPOILER ALERT ⚠️
use codetrotter_aoc_2019_solutions::day_06::{INPUT, input_generator, solve_part_2}; assert_eq!(solve_part_2(&mut input_generator(INPUT)), 370);