From 3c29cdabc808967b6a0a3ea395b7b0f9af4e49c1 Mon Sep 17 00:00:00 2001 From: ictrobot Date: Sun, 22 Dec 2024 16:08:25 +0000 Subject: [PATCH] Add feature to control if 2024 day 21 cost matrices are computed at compile time --- crates/year2024/Cargo.toml | 1 + crates/year2024/src/day21.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/year2024/Cargo.toml b/crates/year2024/Cargo.toml index a33ac8e..ed27ec0 100644 --- a/crates/year2024/Cargo.toml +++ b/crates/year2024/Cargo.toml @@ -12,3 +12,4 @@ utils = { path = "../utils" } [features] unsafe = ["utils/unsafe"] +const_lut = [] diff --git a/crates/year2024/src/day21.rs b/crates/year2024/src/day21.rs index 0604d50..fcf5f89 100644 --- a/crates/year2024/src/day21.rs +++ b/crates/year2024/src/day21.rs @@ -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 { @@ -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 {