From 44c0d12a0105d63bc38473ea6c81ac57f0006165 Mon Sep 17 00:00:00 2001 From: "Narazaki, Shuji" Date: Sat, 11 Mar 2023 09:51:36 +0900 Subject: [PATCH] y2022 day19: introduce upper bounds of robots (resolve #20) --- src/y2022/day19.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/y2022/day19.rs b/src/y2022/day19.rs index b74530ac..aee52671 100644 --- a/src/y2022/day19.rs +++ b/src/y2022/day19.rs @@ -38,6 +38,7 @@ impl Calculation for [usize; 4] { struct Blueprint { id: usize, trans: [[usize; 4]; 4], + limits: [usize; 4], } #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -92,6 +93,9 @@ impl Blueprint { } } for (i, requires) in self.trans.iter().enumerate() { + if self.limits[i] <= state.robots[i] { + continue; + } // check if all the required stuffs can be generated if !requires .iter() @@ -170,6 +174,12 @@ impl AdventOfCode for Puzzle { [0, 0, 0, nth!(3)], [0, 0, 0, nth!(2)], ], + limits: [ + usize::MAX, + nth!(7), + nth!(5), + (nth!(6).max(nth!(4))).max(nth!(3).max(nth!(2))), + ], }); } Ok(())