Add operator set creation
This commit is contained in:
@@ -3,15 +3,39 @@
|
||||
// Run command: cargo run ./input.txt
|
||||
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
env,
|
||||
error::Error,
|
||||
fs::File,
|
||||
io::{BufReader, prelude::*},
|
||||
path::Component,
|
||||
sync::RwLockWriteGuard,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
fn create_operator_set_recurse(
|
||||
operators_permutation_set: &mut HashSet<Vec<bool>>,
|
||||
operators: Vec<bool>,
|
||||
) {
|
||||
operators_permutation_set.insert(operators.clone());
|
||||
if !operators.contains(&false) {
|
||||
return;
|
||||
}
|
||||
|
||||
for i in 0..operators.len() {
|
||||
if operators[i] {
|
||||
continue;
|
||||
}
|
||||
let mut new_operators = operators.clone();
|
||||
new_operators[i] = true;
|
||||
create_operator_set_recurse(operators_permutation_set, new_operators);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_operator_set(num_of_operators: usize) -> HashSet<Vec<bool>> {
|
||||
let mut operator_sets: HashSet<Vec<bool>> = HashSet::new();
|
||||
create_operator_set_recurse(&mut operator_sets, vec![false; num_of_operators]);
|
||||
operator_sets
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Ops {
|
||||
Multiply,
|
||||
Add,
|
||||
@@ -50,6 +74,11 @@ impl Equation {
|
||||
.collect::<Result<Vec<i32>, String>>()?;
|
||||
Ok(Equation { answer, components })
|
||||
}
|
||||
|
||||
fn solvable(&self) -> bool {
|
||||
let op_combination: HashSet<HashSet<i32>> = HashSet::new();
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
@@ -73,5 +102,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
println!("{:?}", equations);
|
||||
|
||||
let operator_set = create_operator_set(3);
|
||||
println!("{:?}", operator_set);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user