Skip to content

Commit 3c29cda

Browse files
committed
Add feature to control if 2024 day 21 cost matrices are computed at compile time
1 parent e5729c4 commit 3c29cda

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

crates/year2024/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ utils = { path = "../utils" }
1212

1313
[features]
1414
unsafe = ["utils/unsafe"]
15+
const_lut = []

crates/year2024/src/day21.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ enum DirectionalKeypad {
2323
Left = 1, Down = 2, Right = 3,
2424
}
2525

26+
#[cfg(feature = "const_lut")]
2627
static PART1_MATRIX: [[u64; 11]; 11] = num_matrix(2);
28+
#[cfg(feature = "const_lut")]
2729
static PART2_MATRIX: [[u64; 11]; 11] = num_matrix(25);
2830

2931
impl Day21 {
@@ -37,12 +39,20 @@ impl Day21 {
3739

3840
#[must_use]
3941
pub fn part1(&self) -> u64 {
40-
self.complexity(&PART1_MATRIX)
42+
#[cfg(feature = "const_lut")]
43+
return self.complexity(&PART1_MATRIX);
44+
45+
#[cfg(not(feature = "const_lut"))]
46+
return self.complexity(&num_matrix(2));
4147
}
4248

4349
#[must_use]
4450
pub fn part2(&self) -> u64 {
45-
self.complexity(&PART2_MATRIX)
51+
#[cfg(feature = "const_lut")]
52+
return self.complexity(&PART2_MATRIX);
53+
54+
#[cfg(not(feature = "const_lut"))]
55+
return self.complexity(&num_matrix(25));
4656
}
4757

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

0 commit comments

Comments
 (0)