|
@@ -194,11 +194,113 @@ impl Sudoku {
|
|
// Get the value
|
|
// Get the value
|
|
let value = self.possible[i as usize].iter().next().cloned().unwrap();
|
|
let value = self.possible[i as usize].iter().next().cloned().unwrap();
|
|
// Found one!
|
|
// Found one!
|
|
- println!("Set {:?} to {}", xy(i), value);
|
|
|
|
|
|
+ println!("Set1 {:?} to {}", xy(i), value);
|
|
self.set(xy(i).0, xy(i).1, value);
|
|
self.set(xy(i).0, xy(i).1, value);
|
|
found_something = true;
|
|
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
|
|
found_something
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -279,7 +381,10 @@ fn main() {
|
|
|
|
|
|
while s.solve() {
|
|
while s.solve() {
|
|
println!("Try it again...");
|
|
println!("Try it again...");
|
|
|
|
+ s.display();
|
|
|
|
+ s.display_possible();
|
|
}
|
|
}
|
|
|
|
+
|
|
s.display();
|
|
s.display();
|
|
s.display_possible();
|
|
s.display_possible();
|
|
|
|
|