|
@@ -20,6 +20,17 @@ pub struct AnyGroup {
|
|
pub cell: Vec<usize>,
|
|
pub cell: Vec<usize>,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/// Find the number of digits needed to display given number.
|
|
|
|
+fn find_number_width(mut number:usize) -> usize {
|
|
|
|
+ let mut size:usize = 1;
|
|
|
|
+ number /= 10;
|
|
|
|
+ while number > 0 {
|
|
|
|
+ size += 1;
|
|
|
|
+ number /= 10;
|
|
|
|
+ }
|
|
|
|
+ size
|
|
|
|
+}
|
|
|
|
+
|
|
impl AnyGroup {
|
|
impl AnyGroup {
|
|
pub fn new(board_size: u8) -> Self {
|
|
pub fn new(board_size: u8) -> Self {
|
|
let width = board_size as usize * board_size as usize;
|
|
let width = board_size as usize * board_size as usize;
|
|
@@ -102,37 +113,39 @@ impl AnyGroup {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn display(&self) {
|
|
pub fn display(&self) {
|
|
|
|
+ let max_index_size = find_number_width(self.width as usize * self.width as usize);
|
|
|
|
+
|
|
println!("rows:");
|
|
println!("rows:");
|
|
- println!("{:?}", self.row);
|
|
|
|
|
|
+ // println!("{:?}", self.row);
|
|
for i in 0..self.width {
|
|
for i in 0..self.width {
|
|
let r = self.row(i);
|
|
let r = self.row(i);
|
|
print!("[{:2}]: ", i);
|
|
print!("[{:2}]: ", i);
|
|
for j in r {
|
|
for j in r {
|
|
let xy = self.xy(*j);
|
|
let xy = self.xy(*j);
|
|
- print!("{:2}({:2},{:2}) ", j, xy.0, xy.1);
|
|
|
|
|
|
+ print!("{0:1$}({2:2},{3:2}) ", j, max_index_size, xy.0, xy.1);
|
|
}
|
|
}
|
|
println!("");
|
|
println!("");
|
|
}
|
|
}
|
|
println!("columns:");
|
|
println!("columns:");
|
|
- println!("{:?}", self.column);
|
|
|
|
|
|
+ // println!("{:?}", self.column);
|
|
for i in 0..self.width {
|
|
for i in 0..self.width {
|
|
let r = self.column(i);
|
|
let r = self.column(i);
|
|
print!("[{:2}]: ", i);
|
|
print!("[{:2}]: ", i);
|
|
for j in r {
|
|
for j in r {
|
|
let xy = self.xy(*j);
|
|
let xy = self.xy(*j);
|
|
- print!("{:2}({:2},{:2}) ", j, xy.0, xy.1);
|
|
|
|
|
|
+ print!("{0:1$}({2:2},{3:2}) ", j, max_index_size, xy.0, xy.1);
|
|
}
|
|
}
|
|
println!("");
|
|
println!("");
|
|
}
|
|
}
|
|
|
|
|
|
println!("cells:");
|
|
println!("cells:");
|
|
- println!("{:?}", self.cell);
|
|
|
|
|
|
+ // println!("{:?}", self.cell);
|
|
for i in 0..self.width {
|
|
for i in 0..self.width {
|
|
let r = self.cell(i);
|
|
let r = self.cell(i);
|
|
print!("[{:2}]: ", i);
|
|
print!("[{:2}]: ", i);
|
|
for j in r {
|
|
for j in r {
|
|
let xy = self.xy(*j);
|
|
let xy = self.xy(*j);
|
|
- print!("{:2}({:2},{:2}) ", j, xy.0, xy.1);
|
|
|
|
|
|
+ print!("{0:1$}({2:2},{3:2}) ", j, max_index_size, xy.0, xy.1);
|
|
}
|
|
}
|
|
println!("");
|
|
println!("");
|
|
}
|
|
}
|
|
@@ -551,6 +564,8 @@ mod tests {
|
|
fn check_dynamic() {
|
|
fn check_dynamic() {
|
|
let g = AnyGroup::new(3);
|
|
let g = AnyGroup::new(3);
|
|
g.display();
|
|
g.display();
|
|
|
|
+ let g = AnyGroup::new(4);
|
|
|
|
+ g.display();
|
|
assert!(false);
|
|
assert!(false);
|
|
}
|
|
}
|
|
}
|
|
}
|