Function advent_of_code_2021::day_2::navigate_and_aim [−][src]
Expand description
This starts with the submarine at the origin, with a third variable ‘aim’ also set to 0. The position and aim are updated using the following rules:
- Forward: Increase the horizontal position by the magnitude, increase the depth by
(magnitude x current aim) - Up: Decrease the aim by the magnitude
- Down: Increase the aim by the magnitude
The final position and aim after applying all the instructions in order is returned as a tuple
(horizontal_position, depth, aim)
Example from puzzle specification
let input = vec![
(FORWARD, 5),
(DOWN, 5),
(FORWARD, 8),
(UP, 3),
(DOWN, 8),
(FORWARD, 2),
]
assert_eq!(navigate_and_aim(&input), (15, 60, 10))