Steve Thielemann преди 9 месеца
родител
ревизия
47c5a630e4
променени са 4 файла, в които са добавени 21 реда и са изтрити 22 реда
  1. 3 3
      sudoku/src/group.rs
  2. 2 2
      sudoku/src/ksudoku.rs
  3. 1 1
      sudoku/src/lib.rs
  4. 15 16
      sudoku/src/sudoku.rs

+ 3 - 3
sudoku/src/group.rs

@@ -16,7 +16,7 @@ pub struct Group {
     pub items: [u8; WIDTH as usize],
 }
 
-struct Group2([u8;WIDTH as usize]);
+struct Group2([u8; WIDTH as usize]);
 
 /// Group of positions for rows.
 const GROUP_ROW: [Group; 9] = [
@@ -414,8 +414,8 @@ pub fn for_cell(i: u8) -> &'static Group {
 }
 
 /// Which cell contains this x,y?
-pub fn which_cell(x:u8, y:u8) -> u8 {
-    (x/3)+(y/3)*3
+pub fn which_cell(x: u8, y: u8) -> u8 {
+    (x / 3) + (y / 3) * 3
 }
 
 #[cfg(test)]

+ 2 - 2
sudoku/src/ksudoku.rs

@@ -3,8 +3,8 @@
 use serde_derive::{Deserialize, Serialize};
 use serde_xml_rs::{from_reader, from_str, to_string};
 
-use std::fs::File;
 use std::error::Error;
+use std::fs::File;
 
 #[derive(Debug, Serialize, Deserialize, PartialEq)]
 struct Graph {
@@ -39,4 +39,4 @@ pub fn load_ksudoku(filename: std::path::PathBuf) -> Result<String, Box<dyn Erro
     let fh = File::open(filename)?;
     let puzzle: Ksudoku = from_reader(fh)?;
     Ok(puzzle.game.puzzle.values.clone())
-}
+}

+ 1 - 1
sudoku/src/lib.rs

@@ -1,6 +1,6 @@
 pub mod group;
-pub mod sudoku;
 pub mod ksudoku;
+pub mod sudoku;
 
 // use crate::group::*;
 use crate::sudoku::*;

+ 15 - 16
sudoku/src/sudoku.rs

@@ -77,7 +77,7 @@ impl Sudoku {
 
         for ch in s.chars() {
             if ch != blank {
-                self.set(x,y, (ch as u8-start_ch as u8) +1);
+                self.set(x, y, (ch as u8 - start_ch as u8) + 1);
             }
             y += 1;
             if y >= WIDTH {
@@ -95,21 +95,21 @@ impl Sudoku {
 
         for ch in s.chars() {
             if ch != blank {
-                self.set(xy(i).0, xy(i).1, (ch as u8-start_ch as u8) +1);
+                self.set(xy(i).0, xy(i).1, (ch as u8 - start_ch as u8) + 1);
             }
             i += 1;
         }
     }
 
-    pub fn save_to_tld(&self, mut start_ch:char, blank: char) -> String {
+    pub fn save_to_tld(&self, mut start_ch: char, blank: char) -> String {
         let mut result = String::new();
         result.reserve(MAX_SIZE as usize);
-        start_ch = (start_ch as u8 -1) as char;
-        let mut x:u8 = 0;
-        let mut y:u8 = 0;
+        start_ch = (start_ch as u8 - 1) as char;
+        let mut x: u8 = 0;
+        let mut y: u8 = 0;
 
         for i in 0..MAX_SIZE {
-            if self.board[pos(x,y) as usize] == 0 {
+            if self.board[pos(x, y) as usize] == 0 {
                 result.push(blank);
             } else {
                 result.push((start_ch as u8 + self.board[i as usize]) as char);
@@ -117,16 +117,16 @@ impl Sudoku {
             y += 1;
             if y >= WIDTH {
                 y = 0;
-                x +=1;
+                x += 1;
             }
         }
         result
     }
 
-    pub fn save_to_tlr(&self, mut start_ch:char, blank: char) -> String {
+    pub fn save_to_tlr(&self, mut start_ch: char, blank: char) -> String {
         let mut result = String::new();
         result.reserve(MAX_SIZE as usize);
-        start_ch = (start_ch as u8 -1) as char;
+        start_ch = (start_ch as u8 - 1) as char;
         for i in 0..MAX_SIZE {
             if self.board[i as usize] == 0 {
                 result.push(blank);
@@ -139,19 +139,19 @@ impl Sudoku {
     pub fn set(&mut self, x: u8, y: u8, value: u8) {
         self.board[pos(x, y) as usize] = value;
         // Ok, update the possible
-        let mut g = for_row(y); 
+        let mut g = for_row(y);
         // g.for_row(x, y);
         for g in g.items {
             // remove value from these sets.
             self.possible[g as usize].take(&value);
         }
-        g = for_column(x); 
+        g = for_column(x);
         // g.for_column(x, y);
         for g in g.items {
             // remove value from these sets.
             self.possible[g as usize].take(&value);
         }
-        g = for_cell(which_cell(x,y)); 
+        g = for_cell(which_cell(x, y));
         // g.for_block(x, y);
         for g in g.items {
             // remove value from these sets.
@@ -169,13 +169,13 @@ impl Sudoku {
             // remove value from these sets.
             self.possible[g as usize].take(&value);
         }
-        
+
         g.for_column(x, y);
         for g in g.items {
             // remove value from these sets.
             self.possible[g as usize].take(&value);
         }
-        
+
         g.for_block(x, y);
         for g in g.items {
             // remove value from these sets.
@@ -184,7 +184,6 @@ impl Sudoku {
         self.possible[pos(x, y) as usize].clear();
     }
 
-
     pub fn display(&self) {
         println!("╔═══╦═══╦═══╗");
         for y in 0..WIDTH {