Working on day 7

master
Joey Pollack 1 year ago
parent 58a5c05cfc
commit 5c4c81ea87

@ -8,10 +8,12 @@
******************************************************************************/ ******************************************************************************/
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub enum Operators pub enum Operator
{ {
Add, Add,
Mult, Mult,
NumOperators,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -45,6 +47,7 @@ impl Equation
values.push(v.parse::<i64>().expect(&format!("ERROR: Failed to parse value: {}", v))); values.push(v.parse::<i64>().expect(&format!("ERROR: Failed to parse value: {}", v)));
} }
Equation { values, result } Equation { values, result }
} }
@ -59,12 +62,42 @@ impl Equation
println!(); 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! // NOTE: Operators are always evaluated left-to-right, not according to precedence rules!
pub fn can_be_true(self: &Equation) -> Option<Vec<Operators>> pub fn validate(self: &Equation) -> Option<Vec<Operator>>
{ {
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 None
} }
pub fn oper_sequence_is_valid(self: &Equation, opers: &Vec<Operator>) -> bool
{
// let actual_result = 0;
// for oper in opers
// {
// match oper
// {
// Operator::Add =>
// }
// }
false
}
} }
Loading…
Cancel
Save