Better permutation creation
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user