Move over to using enum
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
mod operator_set;
|
||||
|
||||
use operator_set::create_operator_set;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Ops {
|
||||
Multiply,
|
||||
Add,
|
||||
}
|
||||
use operator_set::{Op, create_operator_set};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Equation {
|
||||
@@ -56,16 +50,13 @@ impl Equation {
|
||||
&self.components
|
||||
}
|
||||
|
||||
fn compute_answer(&self, operators: &[bool]) -> i64 {
|
||||
fn compute_answer(&self, operators: &[Op]) -> i64 {
|
||||
let mut accumulator = self.components[0];
|
||||
|
||||
for (i, op_bool) in operators.iter().enumerate() {
|
||||
if *op_bool {
|
||||
// Multiply
|
||||
accumulator *= self.components[i + 1];
|
||||
} else {
|
||||
// Add
|
||||
accumulator += self.components[i + 1];
|
||||
for (i, op) in operators.iter().enumerate() {
|
||||
match op {
|
||||
Op::Multiply => accumulator *= self.components[i + 1],
|
||||
Op::Add => accumulator += self.components[i + 1],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user