|
@@ -12,16 +12,18 @@ const WIDTH: u8 = 9;
|
|
|
/// Define a Group of sudoku positions.
|
|
|
/// This defines rows, columns, and cells for analysis.
|
|
|
#[derive(PartialEq)]
|
|
|
+pub struct Group( pub [u8; WIDTH as usize]);
|
|
|
+
|
|
|
+/*
|
|
|
pub struct Group {
|
|
|
pub items: [u8; WIDTH as usize],
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
-struct Group2([u8; WIDTH as usize]);
|
|
|
|
|
|
/// Group of positions for rows.
|
|
|
const GROUP_ROW: [Group; 9] = [
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ Group([
|
|
|
pos1(1, 1),
|
|
|
pos1(2, 1),
|
|
|
pos1(3, 1),
|
|
@@ -31,10 +33,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 1),
|
|
|
pos1(8, 1),
|
|
|
pos1(9, 1),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+ Group ([
|
|
|
pos1(1, 2),
|
|
|
pos1(2, 2),
|
|
|
pos1(3, 2),
|
|
@@ -44,10 +44,9 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 2),
|
|
|
pos1(8, 2),
|
|
|
pos1(9, 2),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+
|
|
|
+ Group ([
|
|
|
pos1(1, 3),
|
|
|
pos1(2, 3),
|
|
|
pos1(3, 3),
|
|
@@ -57,10 +56,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 3),
|
|
|
pos1(8, 3),
|
|
|
pos1(9, 3),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+ Group ([
|
|
|
pos1(1, 4),
|
|
|
pos1(2, 4),
|
|
|
pos1(3, 4),
|
|
@@ -70,10 +67,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 4),
|
|
|
pos1(8, 4),
|
|
|
pos1(9, 4),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+ Group([
|
|
|
pos1(1, 5),
|
|
|
pos1(2, 5),
|
|
|
pos1(3, 5),
|
|
@@ -83,10 +78,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 5),
|
|
|
pos1(8, 5),
|
|
|
pos1(9, 5),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+ Group([
|
|
|
pos1(1, 6),
|
|
|
pos1(2, 6),
|
|
|
pos1(3, 6),
|
|
@@ -96,10 +89,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 6),
|
|
|
pos1(8, 6),
|
|
|
pos1(9, 6),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+ Group([
|
|
|
pos1(1, 7),
|
|
|
pos1(2, 7),
|
|
|
pos1(3, 7),
|
|
@@ -109,10 +100,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 7),
|
|
|
pos1(8, 7),
|
|
|
pos1(9, 7),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+]),
|
|
|
+ Group ([
|
|
|
pos1(1, 8),
|
|
|
pos1(2, 8),
|
|
|
pos1(3, 8),
|
|
@@ -122,10 +111,8 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 8),
|
|
|
pos1(8, 8),
|
|
|
pos1(9, 8),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(1, 9),
|
|
|
pos1(2, 9),
|
|
|
pos1(3, 9),
|
|
@@ -135,14 +122,12 @@ const GROUP_ROW: [Group; 9] = [
|
|
|
pos1(7, 9),
|
|
|
pos1(8, 9),
|
|
|
pos1(9, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
+ ])
|
|
|
];
|
|
|
|
|
|
/// Group of positions for columns.
|
|
|
const GROUP_COLUMN: [Group; 9] = [
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ Group([
|
|
|
pos1(1, 1),
|
|
|
pos1(1, 2),
|
|
|
pos1(1, 3),
|
|
@@ -152,10 +137,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(1, 7),
|
|
|
pos1(1, 8),
|
|
|
pos1(1, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(2, 1),
|
|
|
pos1(2, 2),
|
|
|
pos1(2, 3),
|
|
@@ -165,10 +148,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(2, 7),
|
|
|
pos1(2, 8),
|
|
|
pos1(2, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(3, 1),
|
|
|
pos1(3, 2),
|
|
|
pos1(3, 3),
|
|
@@ -178,10 +159,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(3, 7),
|
|
|
pos1(3, 8),
|
|
|
pos1(3, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(4, 1),
|
|
|
pos1(4, 2),
|
|
|
pos1(4, 3),
|
|
@@ -191,10 +170,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(4, 7),
|
|
|
pos1(4, 8),
|
|
|
pos1(4, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(5, 1),
|
|
|
pos1(5, 2),
|
|
|
pos1(5, 3),
|
|
@@ -204,10 +181,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(5, 7),
|
|
|
pos1(5, 8),
|
|
|
pos1(5, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(6, 1),
|
|
|
pos1(6, 2),
|
|
|
pos1(6, 3),
|
|
@@ -217,10 +192,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(6, 7),
|
|
|
pos1(6, 8),
|
|
|
pos1(6, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(7, 1),
|
|
|
pos1(7, 2),
|
|
|
pos1(7, 3),
|
|
@@ -230,10 +203,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(7, 7),
|
|
|
pos1(7, 8),
|
|
|
pos1(7, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(8, 1),
|
|
|
pos1(8, 2),
|
|
|
pos1(8, 3),
|
|
@@ -243,10 +214,8 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(8, 7),
|
|
|
pos1(8, 8),
|
|
|
pos1(8, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(9, 1),
|
|
|
pos1(9, 2),
|
|
|
pos1(9, 3),
|
|
@@ -256,14 +225,12 @@ const GROUP_COLUMN: [Group; 9] = [
|
|
|
pos1(9, 7),
|
|
|
pos1(9, 8),
|
|
|
pos1(9, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
+ ]),
|
|
|
];
|
|
|
|
|
|
/// Group of positions for cells (3x3 grid).
|
|
|
const GROUP_CELL: [Group; 9] = [
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ Group ([
|
|
|
pos1(1, 1),
|
|
|
pos1(2, 1),
|
|
|
pos1(3, 1),
|
|
@@ -273,10 +240,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(1, 3),
|
|
|
pos1(2, 3),
|
|
|
pos1(3, 3),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(4, 1),
|
|
|
pos1(5, 1),
|
|
|
pos1(6, 1),
|
|
@@ -286,10 +251,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(4, 3),
|
|
|
pos1(5, 3),
|
|
|
pos1(6, 3),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(7, 1),
|
|
|
pos1(8, 1),
|
|
|
pos1(9, 1),
|
|
@@ -299,10 +262,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(7, 3),
|
|
|
pos1(8, 3),
|
|
|
pos1(9, 3),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(1, 4),
|
|
|
pos1(2, 4),
|
|
|
pos1(3, 4),
|
|
@@ -312,10 +273,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(1, 6),
|
|
|
pos1(2, 6),
|
|
|
pos1(3, 6),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(4, 4),
|
|
|
pos1(5, 4),
|
|
|
pos1(6, 4),
|
|
@@ -325,10 +284,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(4, 6),
|
|
|
pos1(5, 6),
|
|
|
pos1(6, 6),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(7, 4),
|
|
|
pos1(8, 4),
|
|
|
pos1(9, 4),
|
|
@@ -338,10 +295,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(7, 6),
|
|
|
pos1(8, 6),
|
|
|
pos1(9, 6),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(1, 7),
|
|
|
pos1(2, 7),
|
|
|
pos1(3, 7),
|
|
@@ -351,10 +306,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(1, 9),
|
|
|
pos1(2, 9),
|
|
|
pos1(3, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(4, 7),
|
|
|
pos1(5, 7),
|
|
|
pos1(6, 7),
|
|
@@ -364,10 +317,8 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(4, 9),
|
|
|
pos1(5, 9),
|
|
|
pos1(6, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
- Group {
|
|
|
- items: [
|
|
|
+ ]),
|
|
|
+ Group ([
|
|
|
pos1(7, 7),
|
|
|
pos1(8, 7),
|
|
|
pos1(9, 7),
|
|
@@ -377,26 +328,25 @@ const GROUP_CELL: [Group; 9] = [
|
|
|
pos1(7, 9),
|
|
|
pos1(8, 9),
|
|
|
pos1(9, 9),
|
|
|
- ],
|
|
|
- },
|
|
|
+ ]),
|
|
|
];
|
|
|
|
|
|
impl fmt::Debug for Group {
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
if f.alternate() {
|
|
|
write!(f, "Group {{ {}[{},{}], {}[{},{}], {}[{},{}], {}[{},{}], {}[{},{}], {}[{},{}], {}[{},{}], {}[{},{}], {}[{},{}] }}",
|
|
|
- self.items[0], xy(self.items[0]).0, xy(self.items[0]).1,
|
|
|
- self.items[1], xy(self.items[1]).0, xy(self.items[1]).1,
|
|
|
- self.items[2], xy(self.items[2]).0, xy(self.items[2]).1,
|
|
|
- self.items[3], xy(self.items[3]).0, xy(self.items[3]).1,
|
|
|
- self.items[4], xy(self.items[4]).0, xy(self.items[4]).1,
|
|
|
- self.items[5], xy(self.items[5]).0, xy(self.items[5]).1,
|
|
|
- self.items[6], xy(self.items[6]).0, xy(self.items[6]).1,
|
|
|
- self.items[7], xy(self.items[7]).0, xy(self.items[7]).1,
|
|
|
- self.items[8], xy(self.items[8]).0, xy(self.items[8]).1,
|
|
|
+ self.0[0], xy(self.0[0]).0, xy(self.0[0]).1,
|
|
|
+ self.0[1], xy(self.0[1]).0, xy(self.0[1]).1,
|
|
|
+ self.0[2], xy(self.0[2]).0, xy(self.0[2]).1,
|
|
|
+ self.0[3], xy(self.0[3]).0, xy(self.0[3]).1,
|
|
|
+ self.0[4], xy(self.0[4]).0, xy(self.0[4]).1,
|
|
|
+ self.0[5], xy(self.0[5]).0, xy(self.0[5]).1,
|
|
|
+ self.0[6], xy(self.0[6]).0, xy(self.0[6]).1,
|
|
|
+ self.0[7], xy(self.0[7]).0, xy(self.0[7]).1,
|
|
|
+ self.0[8], xy(self.0[8]).0, xy(self.0[8]).1,
|
|
|
)
|
|
|
} else {
|
|
|
- f.debug_struct("Group").field("items", &self.items).finish()
|
|
|
+ f.debug_struct("Group").field("items", &self).finish()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -466,19 +416,19 @@ mod tests {
|
|
|
|
|
|
impl Group {
|
|
|
pub fn new() -> Self {
|
|
|
- Group {
|
|
|
- items: [0; WIDTH as usize],
|
|
|
- }
|
|
|
+ Group (
|
|
|
+ [0; WIDTH as usize],
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
pub fn for_column(&mut self, x: u8, _y: u8) {
|
|
|
for y in 0..WIDTH {
|
|
|
- self.items[y as usize] = pos(x, y);
|
|
|
+ self.0[y as usize] = pos(x, y);
|
|
|
}
|
|
|
}
|
|
|
pub fn for_row(&mut self, _x: u8, y: u8) {
|
|
|
for x in 0..WIDTH {
|
|
|
- self.items[x as usize] = pos(x, y);
|
|
|
+ self.0[x as usize] = pos(x, y);
|
|
|
}
|
|
|
}
|
|
|
pub fn for_block(&mut self, x: u8, y: u8) {
|
|
@@ -489,7 +439,7 @@ impl Group {
|
|
|
let ix = i % 3;
|
|
|
let iy = i / 3;
|
|
|
// println!("i = {}, sb.x = {} sb.y = {}, ix = {} iy = {}", i, sb_x, sb_y, ix, iy);
|
|
|
- self.items[i as usize] = pos(sb_x + ix, sb_y + iy);
|
|
|
+ self.0[i as usize] = pos(sb_x + ix, sb_y + iy);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -501,7 +451,7 @@ impl Group {
|
|
|
|
|
|
pub fn display(&self) {
|
|
|
for i in 0..WIDTH {
|
|
|
- let v = self.items[i as usize];
|
|
|
+ let v = self.0[i as usize];
|
|
|
print!("{} [{},{}] ", v, xy(v).0, xy(v).1);
|
|
|
}
|
|
|
println!("");
|