Function advent_of_code_2021::day_2::navigate [−][src]
Expand description
This starts with the submarine at the origin, and moves using the following rules:
- Forward: Increase the horizontal position by the magnitude
- Up: Decrease the depth by the magnitude
- Down: Increase the depth by the magnitude
The final position after applying all the instructions in order is returned as a tuple
(horizontal_position, depth)
Example from puzzle specification
let input = vec![
(FORWARD, 5),
(DOWN, 5),
(FORWARD, 8),
(UP, 3),
(DOWN, 8),
(FORWARD, 2),
]
assert_eq!(navigate(&input), (15, 10))