Skip to content

Commit

Permalink
y2022 day19: introduce upper bounds of robots (resolve #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnarazk committed Mar 11, 2023
1 parent ff7a60e commit 44c0d12
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/y2022/day19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 44c0d12

Please sign in to comment.