From 775c4a50ca5fc0e0d25ba57675250bc72bfd0780 Mon Sep 17 00:00:00 2001 From: Bearmine Date: Mon, 16 Jun 2025 10:31:36 -0500 Subject: [PATCH] Add operator set creation --- day_07/src/main.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/day_07/src/main.rs b/day_07/src/main.rs index e604e83..5e9b8e4 100644 --- a/day_07/src/main.rs +++ b/day_07/src/main.rs @@ -3,15 +3,39 @@ // Run command: cargo run ./input.txt use std::{ + collections::HashSet, env, error::Error, fs::File, io::{BufReader, prelude::*}, - path::Component, - sync::RwLockWriteGuard, }; -#[derive(Debug)] +fn create_operator_set_recurse( + operators_permutation_set: &mut HashSet>, + operators: Vec, +) { + operators_permutation_set.insert(operators.clone()); + if !operators.contains(&false) { + return; + } + + for i in 0..operators.len() { + if operators[i] { + continue; + } + let mut new_operators = operators.clone(); + new_operators[i] = true; + create_operator_set_recurse(operators_permutation_set, new_operators); + } +} + +fn create_operator_set(num_of_operators: usize) -> HashSet> { + let mut operator_sets: HashSet> = HashSet::new(); + create_operator_set_recurse(&mut operator_sets, vec![false; num_of_operators]); + operator_sets +} + +#[derive(Debug, Clone, Copy)] enum Ops { Multiply, Add, @@ -50,6 +74,11 @@ impl Equation { .collect::, String>>()?; Ok(Equation { answer, components }) } + + fn solvable(&self) -> bool { + let op_combination: HashSet> = HashSet::new(); + false + } } fn main() -> Result<(), Box> { @@ -73,5 +102,9 @@ fn main() -> Result<(), Box> { } println!("{:?}", equations); + + let operator_set = create_operator_set(3); + println!("{:?}", operator_set); + Ok(()) }