Better permutation creation

This commit is contained in:
2025-06-16 12:58:38 -05:00
parent 72492db6ea
commit e2cb839086
3 changed files with 34 additions and 3 deletions

View File

@@ -1,7 +1,11 @@
mod operator_set;
use std::collections::HashSet;
use operator_set::{Op, create_operator_set};
use crate::equation::operator_set::create_permutations;
#[derive(Debug)]
pub struct Equation {
answer: i64,
@@ -63,8 +67,11 @@ impl Equation {
accumulator
}
pub fn solvable(&self) -> bool {
let op_combinations = create_operator_set(self.components.len() - 1);
pub fn solvable_multiply_add(&self) -> bool {
let op_combinations = create_permutations(
HashSet::from([Op::Add, Op::Multiply]),
self.components.len() - 1,
);
for combination in op_combinations {
if self.answer == self.compute_answer(&combination) {