From 07d9b05904eeae5f2eeec70b1ed0a20103213fed Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 17 Dec 2023 18:26:26 +0100 Subject: [PATCH] =?UTF-8?q?day(17):=20use=20=E2=80=B9From=E2=80=BA=20on=20?= =?UTF-8?q?=E2=80=B9MinHeap=E2=80=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- src/bin/day17.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/bin/day17.rs b/src/bin/day17.rs index 37df9e5..0adf44b 100644 --- a/src/bin/day17.rs +++ b/src/bin/day17.rs @@ -49,19 +49,14 @@ impl Day17 { let (width, height) = (self.map[0].len(), self.map.len()); let goal = Vector2D::new(width as isize - 1, height as isize - 1); - let mut queue: MinHeap = MinHeap::new(); - queue.push(State { - heat_loss: 0, - distance: 0, - position: Vector2D::new(0, 0), - direction: Vector2D::new(1, 0), - }); - queue.push(State { - heat_loss: 0, - distance: 0, - position: Vector2D::new(0, 0), - direction: Vector2D::new(0, 1), - }); + let mut queue: MinHeap = MinHeap::from( + [Vector2D::new(1, 0), Vector2D::new(0, 1)].map(|direction| State { + heat_loss: 0, + distance: 0, + position: Vector2D::new(0, 0), + direction, + }), + ); let mut seen: HashSet<(Vector2D, Vector2D)> = HashSet::new(); while let Some(s) = queue.pop() {