From 5c4c81ea8717f1796edf04a73aa3928ac8d96449 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Wed, 11 Dec 2024 12:37:56 -0500 Subject: [PATCH] Working on day 7 --- crates/day_7/src/equation.rs | 41 ++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/day_7/src/equation.rs b/crates/day_7/src/equation.rs index 3d70c6f..bf867dd 100644 --- a/crates/day_7/src/equation.rs +++ b/crates/day_7/src/equation.rs @@ -8,10 +8,12 @@ ******************************************************************************/ #[derive(Copy, Clone, PartialEq, Debug)] -pub enum Operators +pub enum Operator { Add, Mult, + + NumOperators, } #[derive(Clone, Debug)] @@ -45,6 +47,7 @@ impl Equation values.push(v.parse::().expect(&format!("ERROR: Failed to parse value: {}", v))); } + Equation { values, result } } @@ -59,12 +62,42 @@ impl Equation println!(); } - // Returns None if the equation can not be made true + // Returns: valid order of operations, or None if the equation can not be valid // NOTE: Operators are always evaluated left-to-right, not according to precedence rules! - pub fn can_be_true(self: &Equation) -> Option> + pub fn validate(self: &Equation) -> Option> { - + + let mut operators = vec![Operator::Add; self.values.len() - 1]; + let num_oper_permutations = (Operator::NumOperators as i32).pow(operators.len() as u32); + + for oper_mask in 0..num_oper_permutations + { + for i in 0..operators.len() + { + operators[i] = match oper_mask & (1 << i) == 0 + { + true => Operator::Add, + false => Operator::Mult, + }; + } + + // TODO: Test operator sequence + } None } + + pub fn oper_sequence_is_valid(self: &Equation, opers: &Vec) -> bool + { + // let actual_result = 0; + // for oper in opers + // { + // match oper + // { + // Operator::Add => + // } + // } + + false + } } \ No newline at end of file