|
@@ -349,16 +349,20 @@ impl Sudoku {
|
|
|
for idx in 0..MAX_SIZE {
|
|
|
if self.board[idx as usize] == 0 {
|
|
|
// Ok, there's a blank here
|
|
|
+
|
|
|
let (x,y) = xy(idx);
|
|
|
+ println!("idx={} ({},{})", idx, x, y);
|
|
|
+ self.display();
|
|
|
+
|
|
|
'outer:
|
|
|
for possible in 1..=9 {
|
|
|
- let mut g = for_row(x);
|
|
|
+ let mut g = for_row(y);
|
|
|
for p in g.0 {
|
|
|
if self.board[p as usize] == possible {
|
|
|
continue 'outer;
|
|
|
}
|
|
|
}
|
|
|
- g = for_column(y);
|
|
|
+ g = for_column(x);
|
|
|
for p in g.0 {
|
|
|
if self.board[p as usize] == possible {
|
|
|
continue 'outer;
|
|
@@ -374,9 +378,14 @@ impl Sudoku {
|
|
|
}
|
|
|
|
|
|
// Ok, it could go here!
|
|
|
+ println!("({},{})={}", x, y, possible);
|
|
|
+
|
|
|
self.board[idx as usize] = possible;
|
|
|
if self.puzzle_complete() {
|
|
|
*solutions += 1;
|
|
|
+ println!("**SOLUTION**");
|
|
|
+ self.display();
|
|
|
+ println!("***");
|
|
|
break;
|
|
|
} else {
|
|
|
if self.calculate_possible(solutions) {
|
|
@@ -384,8 +393,9 @@ impl Sudoku {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ self.board[idx as usize] = 0;
|
|
|
+ return false
|
|
|
}
|
|
|
- self.board[idx as usize] = 0;
|
|
|
}
|
|
|
|
|
|
false
|
|
@@ -399,7 +409,6 @@ impl Sudoku {
|
|
|
|
|
|
let mut solutions :u16 = 0;
|
|
|
workset.calculate_possible(&mut solutions);
|
|
|
-
|
|
|
|
|
|
// find number of solutions.
|
|
|
solutions
|