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