Skip to content

Commit

Permalink
Add feature to control if 2024 day 21 cost matrices are computed at c…
Browse files Browse the repository at this point in the history
…ompile time
  • Loading branch information
ictrobot committed Dec 22, 2024
1 parent e5729c4 commit 3c29cda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/year2024/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ utils = { path = "../utils" }

[features]
unsafe = ["utils/unsafe"]
const_lut = []
14 changes: 12 additions & 2 deletions crates/year2024/src/day21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ enum DirectionalKeypad {
Left = 1, Down = 2, Right = 3,
}

#[cfg(feature = "const_lut")]
static PART1_MATRIX: [[u64; 11]; 11] = num_matrix(2);
#[cfg(feature = "const_lut")]
static PART2_MATRIX: [[u64; 11]; 11] = num_matrix(25);

impl Day21 {
Expand All @@ -37,12 +39,20 @@ impl Day21 {

#[must_use]
pub fn part1(&self) -> u64 {
self.complexity(&PART1_MATRIX)
#[cfg(feature = "const_lut")]
return self.complexity(&PART1_MATRIX);

#[cfg(not(feature = "const_lut"))]
return self.complexity(&num_matrix(2));
}

#[must_use]
pub fn part2(&self) -> u64 {
self.complexity(&PART2_MATRIX)
#[cfg(feature = "const_lut")]
return self.complexity(&PART2_MATRIX);

#[cfg(not(feature = "const_lut"))]
return self.complexity(&num_matrix(25));
}

fn complexity(&self, matrix: &[[u64; 11]; 11]) -> u64 {
Expand Down

0 comments on commit 3c29cda

Please sign in to comment.