|
|
@ -44,16 +44,18 @@ pub fn generate_valid_combinations(hand: &Hand) -> Vec<Vec<Tile>> {
|
|
|
|
// Then try to place the equals sign at each possible position
|
|
|
|
// Then try to place the equals sign at each possible position
|
|
|
|
// Since equality is commutative, we only need to try half of the positions
|
|
|
|
// Since equality is commutative, we only need to try half of the positions
|
|
|
|
for equals_idx in 0..(nb_digits / 2) {
|
|
|
|
for equals_idx in 0..(nb_digits / 2) {
|
|
|
|
for operators in operators.iter().permutations(nb_digits - 2) {
|
|
|
|
for nb_operators in 0..=(nb_digits - 2) {
|
|
|
|
merge_expression(&digits, &operators, equals_idx, &mut trial);
|
|
|
|
for operators in operators.iter().permutations(nb_operators) {
|
|
|
|
if let Ok(tokens) = lexer(&trial) {
|
|
|
|
merge_expression(&digits, &operators, equals_idx, &mut trial);
|
|
|
|
if let Ok(expressions) = parse(&tokens) {
|
|
|
|
if let Ok(tokens) = lexer(&trial) {
|
|
|
|
if are_valid_expressions(&expressions) {
|
|
|
|
if let Ok(expressions) = parse(&tokens) {
|
|
|
|
combinations.push(trial.clone());
|
|
|
|
if are_valid_expressions(&expressions) {
|
|
|
|
|
|
|
|
combinations.push(trial.clone());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trial.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trial.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|