From 19fb611438a2bfd9fcdb0968411ee3ae9d590603 Mon Sep 17 00:00:00 2001 From: Maciej Jur Date: Sat, 24 Dec 2022 12:03:10 +0100 Subject: [PATCH] 2022 day 24 rust --- 2022/rust/src/solutions/day24.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/2022/rust/src/solutions/day24.rs b/2022/rust/src/solutions/day24.rs index 668f3a8..fe9f3ea 100644 --- a/2022/rust/src/solutions/day24.rs +++ b/2022/rust/src/solutions/day24.rs @@ -67,7 +67,6 @@ fn manhattan(start: Pos, goal: Pos) -> isize { fn a_star(start: Pos, goal: Pos, dims: (isize, isize), blizzards: &[Blizzard], offset: isize) -> Option { let mut frontier: BinaryHeap = BinaryHeap::new(); - let mut parent: HashMap<(isize, Pos), (isize, Pos)> = HashMap::new(); let mut cost: HashMap<(isize, Pos), isize> = HashMap::from([((offset, start), 0)]); frontier.push(State { cost: 0, position: (offset, start) }); @@ -75,12 +74,10 @@ fn a_star(start: Pos, goal: Pos, dims: (isize, isize), blizzards: &[Blizzard], o if cur_pos == goal { return Some(cur_t) }; let next_t = cur_t + 1; let blizzards = offset_blizzards(blizzards, dims, next_t); - for neighbour in neighbours(cur_pos, dims).filter(|p| !blizzards.contains(p)) { let new_cost = cost.get(&(cur_t, cur_pos)).unwrap() + 1; if !cost.contains_key(&(next_t, neighbour)) || new_cost < cost[&(next_t, neighbour)] { cost.insert((next_t, neighbour), new_cost); - parent.insert((next_t, neighbour), (cur_t, cur_pos)); frontier.push(State { cost: new_cost + manhattan(neighbour, goal), position: (next_t, neighbour),