Explorar el Código

Cleaned up compiler warnings.

Steve Thielemann hace 9 meses
padre
commit
1811ec3256
Se han modificado 2 ficheros con 23 adiciones y 19 borrados
  1. 1 1
      src/main.rs
  2. 22 18
      sudoku/src/sudoku.rs

+ 1 - 1
src/main.rs

@@ -1,4 +1,4 @@
-use clap::{arg, command, value_parser, ArgAction, Command};
+use clap::{arg, command, value_parser, ArgAction};
 use std::path::PathBuf;
 use std::path::PathBuf;
 
 
 // https://docs.rs/clap/latest/clap/_tutorial/chapter_0/index.html
 // https://docs.rs/clap/latest/clap/_tutorial/chapter_0/index.html

+ 22 - 18
sudoku/src/sudoku.rs

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