Steve Thielemann 9 mesiacov pred
rodič
commit
c0d100dc5f
1 zmenil súbory, kde vykonal 361 pridanie a 37 odobranie
  1. 361 37
      src/main.rs

+ 361 - 37
src/main.rs

@@ -51,8 +51,8 @@ const fn pos(x: u8, y: u8) -> u8 {
     x + (y * SIZE as u8)
 }
 
-const fn pos1(x:u8, y:u8) -> u8 {
-    (x-1) + ((y-1) * SIZE as u8)
+const fn pos1(x: u8, y: u8) -> u8 {
+    (x - 1) + ((y - 1) * SIZE as u8)
 }
 
 // Translate post to x,y in board.
@@ -380,40 +380,364 @@ struct Group {
     items: [u8; SIZE as usize],
 }
 
-const ROW : [Group;9] = [
-    Group{ items: [pos1(1,1), pos1(2,1), pos1(3,1), pos1(4,1), pos1(5,1), pos1(6,1), pos1(7,1), pos1(8,1), pos1(9,1)]},
-    Group{ items: [pos1(1,2), pos1(2,2), pos1(3,2), pos1(4,2), pos1(5,2), pos1(6,2), pos1(7,2), pos1(8,2), pos1(9,2)]},
-    Group{ items: [pos1(1,3), pos1(2,3), pos1(3,3), pos1(4,3), pos1(5,3), pos1(6,3), pos1(7,3), pos1(8,3), pos1(9,3)]},
-    Group{ items: [pos1(1,4), pos1(2,4), pos1(3,4), pos1(4,4), pos1(5,4), pos1(6,4), pos1(7,4), pos1(8,4), pos1(9,4)]},
-    Group{ items: [pos1(1,5), pos1(2,5), pos1(3,5), pos1(4,5), pos1(5,5), pos1(6,5), pos1(7,5), pos1(8,5), pos1(9,5)]},
-    Group{ items: [pos1(1,6), pos1(2,6), pos1(3,6), pos1(4,6), pos1(5,6), pos1(6,6), pos1(7,6), pos1(8,6), pos1(9,6)]},
-    Group{ items: [pos1(1,7), pos1(2,7), pos1(3,7), pos1(4,7), pos1(5,7), pos1(6,7), pos1(7,7), pos1(8,7), pos1(9,7)]},
-    Group{ items: [pos1(1,8), pos1(2,8), pos1(3,8), pos1(4,8), pos1(5,8), pos1(6,8), pos1(7,8), pos1(8,8), pos1(9,8)]},
-    Group{ items: [pos1(1,9), pos1(2,9), pos1(3,9), pos1(4,9), pos1(5,9), pos1(6,9), pos1(7,9), pos1(8,9), pos1(9,9)]},
+const ROW: [Group; 9] = [
+    Group {
+        items: [
+            pos1(1, 1),
+            pos1(2, 1),
+            pos1(3, 1),
+            pos1(4, 1),
+            pos1(5, 1),
+            pos1(6, 1),
+            pos1(7, 1),
+            pos1(8, 1),
+            pos1(9, 1),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 2),
+            pos1(2, 2),
+            pos1(3, 2),
+            pos1(4, 2),
+            pos1(5, 2),
+            pos1(6, 2),
+            pos1(7, 2),
+            pos1(8, 2),
+            pos1(9, 2),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 3),
+            pos1(2, 3),
+            pos1(3, 3),
+            pos1(4, 3),
+            pos1(5, 3),
+            pos1(6, 3),
+            pos1(7, 3),
+            pos1(8, 3),
+            pos1(9, 3),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 4),
+            pos1(2, 4),
+            pos1(3, 4),
+            pos1(4, 4),
+            pos1(5, 4),
+            pos1(6, 4),
+            pos1(7, 4),
+            pos1(8, 4),
+            pos1(9, 4),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 5),
+            pos1(2, 5),
+            pos1(3, 5),
+            pos1(4, 5),
+            pos1(5, 5),
+            pos1(6, 5),
+            pos1(7, 5),
+            pos1(8, 5),
+            pos1(9, 5),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 6),
+            pos1(2, 6),
+            pos1(3, 6),
+            pos1(4, 6),
+            pos1(5, 6),
+            pos1(6, 6),
+            pos1(7, 6),
+            pos1(8, 6),
+            pos1(9, 6),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 7),
+            pos1(2, 7),
+            pos1(3, 7),
+            pos1(4, 7),
+            pos1(5, 7),
+            pos1(6, 7),
+            pos1(7, 7),
+            pos1(8, 7),
+            pos1(9, 7),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 8),
+            pos1(2, 8),
+            pos1(3, 8),
+            pos1(4, 8),
+            pos1(5, 8),
+            pos1(6, 8),
+            pos1(7, 8),
+            pos1(8, 8),
+            pos1(9, 8),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 9),
+            pos1(2, 9),
+            pos1(3, 9),
+            pos1(4, 9),
+            pos1(5, 9),
+            pos1(6, 9),
+            pos1(7, 9),
+            pos1(8, 9),
+            pos1(9, 9),
+        ],
+    },
 ];
 
-const COLUMN : [Group;9] = [
-    Group{ items: [pos1(1,1), pos1(1,2), pos1(1,3), pos1(1,4), pos1(1,5), pos1(1,6), pos1(1,7), pos1(1,8), pos1(1,9)]},
-    Group{ items: [pos1(2,1), pos1(2,2), pos1(2,3), pos1(2,4), pos1(2,5), pos1(2,6), pos1(2,7), pos1(2,8), pos1(2,9)]},
-    Group{ items: [pos1(3,1), pos1(3,2), pos1(3,3), pos1(3,4), pos1(3,5), pos1(3,6), pos1(3,7), pos1(3,8), pos1(3,9)]},
-    Group{ items: [pos1(4,1), pos1(4,2), pos1(4,3), pos1(4,4), pos1(4,5), pos1(4,6), pos1(4,7), pos1(4,8), pos1(4,9)]},
-    Group{ items: [pos1(5,1), pos1(5,2), pos1(5,3), pos1(5,4), pos1(5,5), pos1(5,6), pos1(5,7), pos1(5,8), pos1(5,9)]},
-    Group{ items: [pos1(6,1), pos1(6,2), pos1(6,3), pos1(6,4), pos1(6,5), pos1(6,6), pos1(6,7), pos1(6,8), pos1(6,9)]},
-    Group{ items: [pos1(7,1), pos1(7,2), pos1(7,3), pos1(7,4), pos1(7,5), pos1(7,6), pos1(7,7), pos1(7,8), pos1(7,9)]},
-    Group{ items: [pos1(8,1), pos1(8,2), pos1(8,3), pos1(8,4), pos1(8,5), pos1(8,6), pos1(8,7), pos1(8,8), pos1(8,9)]},
-    Group{ items: [pos1(9,1), pos1(9,2), pos1(9,3), pos1(9,4), pos1(9,5), pos1(9,6), pos1(9,7), pos1(9,8), pos1(9,9)]},
+const COLUMN: [Group; 9] = [
+    Group {
+        items: [
+            pos1(1, 1),
+            pos1(1, 2),
+            pos1(1, 3),
+            pos1(1, 4),
+            pos1(1, 5),
+            pos1(1, 6),
+            pos1(1, 7),
+            pos1(1, 8),
+            pos1(1, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(2, 1),
+            pos1(2, 2),
+            pos1(2, 3),
+            pos1(2, 4),
+            pos1(2, 5),
+            pos1(2, 6),
+            pos1(2, 7),
+            pos1(2, 8),
+            pos1(2, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(3, 1),
+            pos1(3, 2),
+            pos1(3, 3),
+            pos1(3, 4),
+            pos1(3, 5),
+            pos1(3, 6),
+            pos1(3, 7),
+            pos1(3, 8),
+            pos1(3, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(4, 1),
+            pos1(4, 2),
+            pos1(4, 3),
+            pos1(4, 4),
+            pos1(4, 5),
+            pos1(4, 6),
+            pos1(4, 7),
+            pos1(4, 8),
+            pos1(4, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(5, 1),
+            pos1(5, 2),
+            pos1(5, 3),
+            pos1(5, 4),
+            pos1(5, 5),
+            pos1(5, 6),
+            pos1(5, 7),
+            pos1(5, 8),
+            pos1(5, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(6, 1),
+            pos1(6, 2),
+            pos1(6, 3),
+            pos1(6, 4),
+            pos1(6, 5),
+            pos1(6, 6),
+            pos1(6, 7),
+            pos1(6, 8),
+            pos1(6, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(7, 1),
+            pos1(7, 2),
+            pos1(7, 3),
+            pos1(7, 4),
+            pos1(7, 5),
+            pos1(7, 6),
+            pos1(7, 7),
+            pos1(7, 8),
+            pos1(7, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(8, 1),
+            pos1(8, 2),
+            pos1(8, 3),
+            pos1(8, 4),
+            pos1(8, 5),
+            pos1(8, 6),
+            pos1(8, 7),
+            pos1(8, 8),
+            pos1(8, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(9, 1),
+            pos1(9, 2),
+            pos1(9, 3),
+            pos1(9, 4),
+            pos1(9, 5),
+            pos1(9, 6),
+            pos1(9, 7),
+            pos1(9, 8),
+            pos1(9, 9),
+        ],
+    },
 ];
 
-const CELL : [Group;9] = [
-    Group{ items: [pos1(1,1), pos1(2,1), pos1(3,1), pos1(1,2), pos1(2,2), pos1(3,2), pos1(1,3), pos1(2,3), pos1(3,3)]},
-    Group{ items: [pos1(4,1), pos1(5,1), pos1(6,1), pos1(4,2), pos1(5,2), pos1(6,2), pos1(4,3), pos1(5,3), pos1(6,3)]},
-    Group{ items: [pos1(7,1), pos1(8,1), pos1(9,1), pos1(7,2), pos1(8,2), pos1(9,2), pos1(7,3), pos1(8,3), pos1(9,3)]},
-    Group{ items: [pos1(1,4), pos1(2,4), pos1(3,4), pos1(1,5), pos1(2,5), pos1(3,5), pos1(1,6), pos1(2,6), pos1(3,6)]},
-    Group{ items: [pos1(4,4), pos1(5,4), pos1(6,4), pos1(4,5), pos1(5,5), pos1(6,5), pos1(4,6), pos1(5,6), pos1(6,6)]},
-    Group{ items: [pos1(7,4), pos1(8,4), pos1(9,4), pos1(7,5), pos1(8,5), pos1(9,5), pos1(7,6), pos1(8,6), pos1(9,6)]},
-    Group{ items: [pos1(1,7), pos1(2,7), pos1(3,7), pos1(1,8), pos1(2,8), pos1(3,8), pos1(1,9), pos1(2,9), pos1(3,9)]},
-    Group{ items: [pos1(4,7), pos1(5,7), pos1(6,7), pos1(4,8), pos1(5,8), pos1(6,8), pos1(4,9), pos1(5,9), pos1(6,9)]},
-    Group{ items: [pos1(7,7), pos1(8,7), pos1(9,7), pos1(7,8), pos1(8,8), pos1(9,8), pos1(7,9), pos1(8,9), pos1(9,9)]},        
+const CELL: [Group; 9] = [
+    Group {
+        items: [
+            pos1(1, 1),
+            pos1(2, 1),
+            pos1(3, 1),
+            pos1(1, 2),
+            pos1(2, 2),
+            pos1(3, 2),
+            pos1(1, 3),
+            pos1(2, 3),
+            pos1(3, 3),
+        ],
+    },
+    Group {
+        items: [
+            pos1(4, 1),
+            pos1(5, 1),
+            pos1(6, 1),
+            pos1(4, 2),
+            pos1(5, 2),
+            pos1(6, 2),
+            pos1(4, 3),
+            pos1(5, 3),
+            pos1(6, 3),
+        ],
+    },
+    Group {
+        items: [
+            pos1(7, 1),
+            pos1(8, 1),
+            pos1(9, 1),
+            pos1(7, 2),
+            pos1(8, 2),
+            pos1(9, 2),
+            pos1(7, 3),
+            pos1(8, 3),
+            pos1(9, 3),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 4),
+            pos1(2, 4),
+            pos1(3, 4),
+            pos1(1, 5),
+            pos1(2, 5),
+            pos1(3, 5),
+            pos1(1, 6),
+            pos1(2, 6),
+            pos1(3, 6),
+        ],
+    },
+    Group {
+        items: [
+            pos1(4, 4),
+            pos1(5, 4),
+            pos1(6, 4),
+            pos1(4, 5),
+            pos1(5, 5),
+            pos1(6, 5),
+            pos1(4, 6),
+            pos1(5, 6),
+            pos1(6, 6),
+        ],
+    },
+    Group {
+        items: [
+            pos1(7, 4),
+            pos1(8, 4),
+            pos1(9, 4),
+            pos1(7, 5),
+            pos1(8, 5),
+            pos1(9, 5),
+            pos1(7, 6),
+            pos1(8, 6),
+            pos1(9, 6),
+        ],
+    },
+    Group {
+        items: [
+            pos1(1, 7),
+            pos1(2, 7),
+            pos1(3, 7),
+            pos1(1, 8),
+            pos1(2, 8),
+            pos1(3, 8),
+            pos1(1, 9),
+            pos1(2, 9),
+            pos1(3, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(4, 7),
+            pos1(5, 7),
+            pos1(6, 7),
+            pos1(4, 8),
+            pos1(5, 8),
+            pos1(6, 8),
+            pos1(4, 9),
+            pos1(5, 9),
+            pos1(6, 9),
+        ],
+    },
+    Group {
+        items: [
+            pos1(7, 7),
+            pos1(8, 7),
+            pos1(9, 7),
+            pos1(7, 8),
+            pos1(8, 8),
+            pos1(9, 8),
+            pos1(7, 9),
+            pos1(8, 9),
+            pos1(9, 9),
+        ],
+    },
 ];
 
 impl fmt::Debug for Group {
@@ -436,22 +760,22 @@ impl fmt::Debug for Group {
     }
 }
 
-fn for_column(i:u8) -> &'static Group {
+fn for_column(i: u8) -> &'static Group {
     &COLUMN[i as usize]
 }
 
-fn for_row(i:u8) -> &'static Group {
+fn for_row(i: u8) -> &'static Group {
     &ROW[i as usize]
 }
 
-fn for_cell(i:u8) -> &'static Group {
+fn for_cell(i: u8) -> &'static Group {
     &CELL[i as usize]
 }
 
 #[cfg(test)]
 mod tests {
     use crate::Group;
-    use crate::{for_column, for_row, for_cell};
+    use crate::{for_cell, for_column, for_row};
 
     #[test]
     fn check_columns() {
@@ -482,7 +806,7 @@ mod tests {
         let mut g = Group::new();
         for i in 0..9 {
             println!("Index={}", i);
-            g.for_block( (i%3)*3, (i/3)*3);
+            g.for_block((i % 3) * 3, (i / 3) * 3);
             let new_g = for_cell(i);
             assert_eq!(g, *new_g);
         }