day 15 task 2

This commit is contained in:
Johannes
2019-12-21 23:14:30 +01:00
parent 73b612d25b
commit 3f6aec0d67

View File

@@ -7,9 +7,9 @@ use Direction::*;
pub fn run() {
let ram = load_ram("input/day15.txt");
task1(ram.clone());
task2(ram.clone());
}
#[allow(dead_code)]
fn task1(ram: RAM) {
let (map, goal) = explore_map(ram);
let shortest_path = map.get_shortest_path_to(Pos(0, 0), goal);
@@ -29,6 +29,21 @@ fn task1(ram: RAM) {
);
}
fn task2(ram: RAM) {
let (map, oxygen) = explore_map(ram);
let max_distance = map
.positions
.iter()
.filter(|(_, c)| **c == '.')
.map(|(pos, _)| map.get_shortest_path_to(oxygen, *pos).len())
.max()
.unwrap();
println!(
"Task 2: time needed to reach most distant room is {} minutes",
max_distance
);
}
fn explore_map(ram: RAM) -> (Map, Pos) {
let mut map = Map {
positions: HashMap::new(),