Parcourir la source

Problems with set2.

It seems to be eating my hashset values.
Eating 1 from 0,7 to be specific.
Steve Thielemann il y a 10 mois
Parent
commit
f6b0f5bd7d
1 fichiers modifiés avec 106 ajouts et 1 suppressions
  1. 106 1
      src/main.rs

+ 106 - 1
src/main.rs

@@ -194,11 +194,113 @@ impl Sudoku {
                 // Get the value
                 let value = self.possible[i as usize].iter().next().cloned().unwrap();
                 // Found one!
-                println!("Set {:?} to {}", xy(i), value);
+                println!("Set1 {:?} to {}", xy(i), value);
                 self.set(xy(i).0, xy(i).1, value);
                 found_something = true;
             }
         }
+
+        /*
+            // Code currently isn't working.
+            // It seems to eat items that I want and need.
+            // Notably 1 from the 0,7.
+
+            // Look for single possibility in a group
+            let mut g = Group::new();
+            for i in 0..SIZE {
+                let (x, y) = xy(i);
+                let mut values: HashSet<u8> = HashSet::new();
+
+                g.for_block(x, y);
+
+                // collect all the possible values within these sets.
+                values.clear();
+                for gidx in 0..SIZE {
+                    for v in g.items[gidx as usize] {
+                        values.insert(v);
+                    }
+                    // values.extend(self.possible[g.items[gidx as usize] as usize].clone());
+                }
+
+                // Ok!  Now, check for singles:
+                for v in values.iter() {
+                    let mut count = 0;
+                    let mut pos = 0;
+                    for gidx in 0..SIZE {
+                        if self.possible[g.items[gidx as usize] as usize].contains(&v) {
+                            count += 1;
+                            pos = g.items[gidx as usize];
+                        }
+                    }
+                    if count == 1 {
+                        let value = self.possible[pos as usize].iter().next().cloned().unwrap();
+                        println!("Set2 {:?} to {}", xy(pos), value);
+                        self.set(xy(pos).0, xy(pos).1, value);
+                        found_something = true;
+                    }
+                }
+
+                g.for_row(x, y);
+
+                // collect all the possible values within these sets.
+                values.clear();
+                for gidx in 0..SIZE {
+                    for v in g.items[gidx as usize] {
+                        values.insert(v);
+                    }
+
+                    // values.extend(self.possible[g.items[gidx as usize] as usize].clone());
+                }
+
+                // Ok!  Now, check for singles:
+                for v in values.iter() {
+                    let mut count = 0;
+                    let mut pos = 0;
+                    for gidx in 0..SIZE {
+                        if self.possible[g.items[gidx as usize] as usize].contains(&v) {
+                            count += 1;
+                            pos = g.items[gidx as usize];
+                        }
+                    }
+                    if count == 1 {
+                        let value = self.possible[pos as usize].iter().next().cloned().unwrap();
+                        println!("Set2 {:?} to {}", xy(pos), value);
+                        self.set(xy(pos).0, xy(pos).1, value);
+                        found_something = true;
+                    }
+                }
+
+                g.for_column(x, y);
+
+                // collect all the possible values within these sets.
+                values.clear();
+                for gidx in 0..SIZE {
+                    for v in g.items[gidx as usize] {
+                        values.insert(v);
+                    }
+
+                    // values.extend(self.possible[g.items[gidx as usize] as usize].clone());
+                }
+
+                // Ok!  Now, check for singles:
+                for v in values.iter() {
+                    let mut count = 0;
+                    let mut pos = 0;
+                    for gidx in 0..SIZE {
+                        if self.possible[g.items[gidx as usize] as usize].contains(&v) {
+                            count += 1;
+                            pos = g.items[gidx as usize];
+                        }
+                    }
+                    if count == 1 {
+                        let value = self.possible[pos as usize].iter().next().cloned().unwrap();
+                        println!("Set2 {:?} to {}", xy(pos), value);
+                        self.set(xy(pos).0, xy(pos).1, value);
+                        found_something = true;
+                    }
+                }
+            }
+        */
         found_something
     }
 }
@@ -279,7 +381,10 @@ fn main() {
 
     while s.solve() {
         println!("Try it again...");
+        s.display();
+        s.display_possible();
     }
+
     s.display();
     s.display_possible();