|
|
|
|
@ -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::<i64>().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<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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|