|
@@ -341,21 +341,15 @@ impl Sudoku {
|
|
|
}
|
|
|
|
|
|
fn calculate_possible(&mut self, solutions: &mut u16) -> bool {
|
|
|
- let backup = Sudoku {
|
|
|
- board: self.board,
|
|
|
- possible: self.possible,
|
|
|
- };
|
|
|
-
|
|
|
- for idx in 0..MAX_SIZE {
|
|
|
+ for idx in 0..MAX_SIZE {
|
|
|
if self.board[idx as usize] == 0 {
|
|
|
// Ok, there's a blank here
|
|
|
|
|
|
- let (x,y) = xy(idx);
|
|
|
+ let (x, y) = xy(idx);
|
|
|
println!("idx={} ({},{})", idx, x, y);
|
|
|
self.display();
|
|
|
|
|
|
- 'outer:
|
|
|
- for possible in 1..=9 {
|
|
|
+ 'outer: for possible in 1..=9 {
|
|
|
let mut g = for_row(y);
|
|
|
for p in g.0 {
|
|
|
if self.board[p as usize] == possible {
|
|
@@ -369,7 +363,7 @@ impl Sudoku {
|
|
|
}
|
|
|
}
|
|
|
// check cell
|
|
|
- let cell = which_cell(x,y);
|
|
|
+ let cell = which_cell(x, y);
|
|
|
g = for_cell(cell);
|
|
|
for p in g.0 {
|
|
|
if self.board[p as usize] == possible {
|
|
@@ -394,7 +388,7 @@ impl Sudoku {
|
|
|
}
|
|
|
}
|
|
|
self.board[idx as usize] = 0;
|
|
|
- return false
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -407,7 +401,7 @@ impl Sudoku {
|
|
|
possible: [Possible(0); MAX_SIZE as usize],
|
|
|
}; // self.possible };
|
|
|
|
|
|
- let mut solutions :u16 = 0;
|
|
|
+ let mut solutions: u16 = 0;
|
|
|
workset.calculate_possible(&mut solutions);
|
|
|
|
|
|
// find number of solutions.
|
|
@@ -612,12 +606,22 @@ impl Sudoku {
|
|
|
}
|
|
|
// Ok, these aren't the ones to save, so:
|
|
|
let rpos = g.0[remove as usize];
|
|
|
- self.possible[rpos as usize].set(values[0], false); /* ).is_some() {
|
|
|
- found_something = true;
|
|
|
- pair_removed = true;
|
|
|
- };
|
|
|
- */
|
|
|
- self.possible[rpos as usize].set(values[1], false);
|
|
|
+ if self.possible[rpos as usize].get(values[0]) {
|
|
|
+ self.possible[rpos as usize].set(values[0], false);
|
|
|
+ found_something = true;
|
|
|
+ pair_removed = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ).is_some() {
|
|
|
+ found_something = true;
|
|
|
+ pair_removed = true;
|
|
|
+ };
|
|
|
+ */
|
|
|
+ if self.possible[rpos as usize].get(values[1]) {
|
|
|
+ self.possible[rpos as usize].set(values[1], false);
|
|
|
+ found_something = true;
|
|
|
+ pair_removed = true;
|
|
|
+ }
|
|
|
/*.is_some() {
|
|
|
found_something = true;
|
|
|
pair_removed = true;
|