day 15 task 2
This commit is contained in:
@@ -7,9 +7,9 @@ use Direction::*;
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
let ram = load_ram("input/day15.txt");
|
let ram = load_ram("input/day15.txt");
|
||||||
task1(ram.clone());
|
task1(ram.clone());
|
||||||
|
task2(ram.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn task1(ram: RAM) {
|
fn task1(ram: RAM) {
|
||||||
let (map, goal) = explore_map(ram);
|
let (map, goal) = explore_map(ram);
|
||||||
let shortest_path = map.get_shortest_path_to(Pos(0, 0), goal);
|
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) {
|
fn explore_map(ram: RAM) -> (Map, Pos) {
|
||||||
let mut map = Map {
|
let mut map = Map {
|
||||||
positions: HashMap::new(),
|
positions: HashMap::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user