This commit is contained in:
Fabian Schmidt 2024-11-28 14:22:42 +01:00
parent 68858a39b1
commit 6b7daff6cc

24
src/bin/problem_32.rs Normal file
View File

@ -0,0 +1,24 @@
use std::collections::HashSet;
use utils::permutation::Permutator;
fn main() {
let mut res = HashSet::new();
let permutator = Permutator::new(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]);
// let perm = vec![7, 2, 5, 4, 3, 9, 1, 8, 6];
for perm in permutator {
for equal_sign_idx in 1..8 {
let possible_product = perm[..equal_sign_idx].iter().fold(0, |acc, e| acc * 10 + e);
for mul_sign_idx in equal_sign_idx..9 {
let a = perm[equal_sign_idx..mul_sign_idx]
.iter()
.fold(0, |acc, e| acc * 10 + e);
let b = perm[mul_sign_idx..].iter().fold(0, |acc, e| acc * 10 + e);
if a * b == possible_product {
res.insert(possible_product);
}
}
}
}
println!("{}", res.iter().sum::<i32>());
}