diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/solvers/intuitive.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/solvers/intuitive.rs b/src/solvers/intuitive.rs index 77f63e5..0899906 100644 --- a/src/solvers/intuitive.rs +++ b/src/solvers/intuitive.rs @@ -100,6 +100,7 @@ impl<T: num::PrimInt> NormalSolver<T> { } fn permute(&mut self, up: usize, index: usize, numbers: &[u32]) { + let chunk = self.permutations.len() / self.h as usize; if index as usize == numbers.len() { //println!("checking {:?}", numbers); if self.check_perm(&numbers) { @@ -108,9 +109,9 @@ impl<T: num::PrimInt> NormalSolver<T> { return; } let mut new_num = Vec::from(numbers); - for i in numbers[index as usize] as usize..up { + for i in numbers[index as usize] as usize..((index + 1) * chunk) { for n in (index + 1)..numbers.len() { - new_num[n] = (n * (self.permutations.len() / self.h as usize)) as u32; + new_num[n] = (n * chunk) as u32; } self.permute(up, index + 1, &new_num); new_num[index] += 1; @@ -124,7 +125,8 @@ impl<T: num::PrimInt> NormalSolver<T> { let mut sums = vec![self.w; self.w as usize]; for (i, num) in nums.iter().enumerate() { let mut sum = 0; - for n in self.permutations[*num as usize][..(self.n - 1) as usize].iter() { + for n in self.permutations[*num as usize][..(self.n - 1 - (self.n & 1)) as usize].iter() + { sum += *n as usize; if sums[sum - 1] != self.w { return false; |