Move over to using enum

This commit is contained in:
2025-06-16 12:24:18 -05:00
parent 3dff9f9bd2
commit 72492db6ea
2 changed files with 23 additions and 26 deletions

View File

@@ -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],
}
}