diff --git a/day_07/src/equation.rs b/day_07/src/equation.rs index c1aceb0..5acf723 100644 --- a/day_07/src/equation.rs +++ b/day_07/src/equation.rs @@ -2,9 +2,7 @@ mod operator_set; use std::collections::HashSet; -use operator_set::{Op, create_operator_set}; - -use crate::equation::operator_set::create_permutations; +use operator_set::{Op, create_permutations}; #[derive(Debug)] pub struct Equation { diff --git a/day_07/src/equation/operator_set.rs b/day_07/src/equation/operator_set.rs index 7fd3bac..f1ce173 100644 --- a/day_07/src/equation/operator_set.rs +++ b/day_07/src/equation/operator_set.rs @@ -8,55 +8,55 @@ pub enum Op { Add, } -type OperatorCache = HashMap>>; +// type OperatorCache = HashMap>>; -static OPERATOR_SET_CACHE: LazyLock> = - LazyLock::new(|| Mutex::new(HashMap::new())); +// static OPERATOR_SET_CACHE: LazyLock> = +// LazyLock::new(|| Mutex::new(HashMap::new())); -fn check_operator_set_cache(cache_key: usize) -> Option>> { - OPERATOR_SET_CACHE.lock().unwrap().get(&cache_key).cloned() -} +// fn check_operator_set_cache(cache_key: usize) -> Option>> { +// OPERATOR_SET_CACHE.lock().unwrap().get(&cache_key).cloned() +// } -fn store_operator_set_in_cache(cache_key: usize, cache_value: HashSet>) { - OPERATOR_SET_CACHE - .lock() - .unwrap() - .insert(cache_key, cache_value); -} +// fn store_operator_set_in_cache(cache_key: usize, cache_value: HashSet>) { +// OPERATOR_SET_CACHE +// .lock() +// .unwrap() +// .insert(cache_key, cache_value); +// } -fn create_operator_set_recurse( - operators_permutation_set: &mut HashSet>, - operators: Vec, -) { - operators_permutation_set.insert(operators.clone()); - if !operators.contains(&Op::Add) { - return; - } +// fn create_operator_set_recurse( +// operators_permutation_set: &mut HashSet>, +// operators: Vec, +// ) { +// operators_permutation_set.insert(operators.clone()); +// if !operators.contains(&Op::Add) { +// return; +// } - for i in 0..operators.len() { - if operators[i] == Op::Multiply { - break; - } - let mut new_operators = operators.clone(); - new_operators[i] = Op::Multiply; - create_operator_set_recurse(operators_permutation_set, new_operators); - } -} +// for i in 0..operators.len() { +// if operators[i] == Op::Multiply { +// break; +// } +// let mut new_operators = operators.clone(); +// new_operators[i] = Op::Multiply; +// create_operator_set_recurse(operators_permutation_set, new_operators); +// } +// } -pub fn create_operator_set(num_of_operators: usize) -> HashSet> { - // Check cache - if let Some(cached_value) = check_operator_set_cache(num_of_operators) { - return cached_value.clone(); - } +// pub fn create_operator_set(num_of_operators: usize) -> HashSet> { +// // Check cache +// if let Some(cached_value) = check_operator_set_cache(num_of_operators) { +// return cached_value.clone(); +// } - let mut operator_sets: HashSet> = HashSet::new(); - create_operator_set_recurse(&mut operator_sets, vec![Op::Add; num_of_operators]); +// let mut operator_sets: HashSet> = HashSet::new(); +// create_operator_set_recurse(&mut operator_sets, vec![Op::Add; num_of_operators]); - // Store value in cache - store_operator_set_in_cache(num_of_operators, operator_sets.clone()); +// // Store value in cache +// store_operator_set_in_cache(num_of_operators, operator_sets.clone()); - operator_sets -} +// operator_sets +// } fn create_permutations_recurse( values: &HashSet,