From 4c07bd4f2e84d06edb760ea0e78a06ef21b1ab39 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 17 Dec 2023 18:11:53 +0100 Subject: [PATCH] day(17): use product of iterators Signed-off-by: Matej Focko --- src/bin/day17.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bin/day17.rs b/src/bin/day17.rs index 8e7457f..37df9e5 100644 --- a/src/bin/day17.rs +++ b/src/bin/day17.rs @@ -1,6 +1,7 @@ use std::collections::HashSet; use aoc_2023::*; +use itertools::iproduct; type Output1 = u32; type Output2 = Output1; @@ -73,14 +74,15 @@ impl Day17 { } seen.insert((s.position, s.direction)); - for steps in min_steps..=max_steps { - for d in [left(&s.direction), right(&s.direction)] { - if !in_range(&self.map, &(s.position + d * steps)) { - continue; - } - - queue.push(s.step(&self.map, d, steps)); + for (steps, d) in iproduct!( + min_steps..=max_steps, + [left(&s.direction), right(&s.direction)] + ) { + if !in_range(&self.map, &(s.position + d * steps)) { + continue; } + + queue.push(s.step(&self.map, d, steps)); } }