pub fn matrix_check(m: &Vec<Vec<u8>>) -> bool {
        for y in 0..9 { // check row
            let mut checked_value: Vec<u8> = vec![];
            // 直接使用 序列操作符[] 获得的是实际的对象而不是一个reference | pointer | copy
            let row = &m[y];
            row.into_iter()
                .for_each(|&x| {
                    checked_value.push(x);
                });
            checked_value.sort();
            if !&SudokuMatrix::arr_repeat_check(&checked_value) {
                return false;
            }
        }

        for x in 0..9 {
            { // check if there is any duplication of numbers in a column
                let mut checked_value: Vec<u8> = vec![];
                for y in 0..9 { // check column
                    checked_value.push(m[y][x]);
                }
                checked_value.sort();
                if !&SudokuMatrix::arr_repeat_check(&checked_value) {
                    return false;
                }
            }
            { // check 3 x 3 matrix
                // x use to point which matrix
                let mut mm_pos: Vec<(usize, usize)> = vec![];
                let y_range = match x / 3 {
                    0 => 0..3,
                    1 => 3..6,
                    2 => 6..9,
                    _ => panic!("index err"),
                };
                let x_range = match x % 3 {
                    0 => 0..3,
                    1 => 3..6,
                    2 => 6..9,
                    _ => panic!("index err"),
                };
                for y in y_range {
                    for x_inm in x_range.clone() {
                        mm_pos.push((y, x_inm));
                    }
                }
                let mut checked_value: Vec<u8> = vec![];
                mm_pos.into_iter().for_each(|(y, x)| {
                    checked_value.push(m[y][x]);
                });
                checked_value.sort();
                if !&SudokuMatrix::arr_repeat_check(&mut checked_value) {
                    return false;
                }
            }
        }
        true
    }
/// Check is the matrix legal
/// return true if matrix legal
///
/// # examples
///
/// ```
/// #[cfg(test)]
/// mod tests {
///     use super::*;
///
///     #[test]
///     fn matrix_check_works() {
///         let test_example = vec![
///             vec![1,2,3,4,5,6,7,8,9],
///             vec![4,5,6,7,8,9,1,2,3],
///             vec![7,8,9,1,2,3,4,5,6],
///             vec![2,3,4,5,6,7,8,9,1],
///             vec![5,6,7,8,9,1,2,3,4],
///             vec![8,9,1,2,3,4,5,6,7],
///             vec![3,4,5,6,7,8,9,1,2],
///             vec![6,7,8,9,1,2,3,4,5],
///             vec![9,1,2,3,4,5,6,7,8],
///         ];
///
///         assert!(matrix_check(&test_example));
///     }
///     #[test]
///     fn matrix_check_works_2() {
///         let test_example = vec![
///             vec![1,2,3,4,5,6,7,8,9],
///             vec![0;9],
///             vec![7,8,9,1,2,3,4,5,6],
///             vec![2,3,4,5,6,7,8,9,1],
///             vec![5,6,7,8,9,1,2,3,4],
///             vec![8,9,1,2,3,4,5,6,7],
///             vec![3,4,5,6,7,8,9,1,2],
///             vec![6,7,8,9,1,2,3,4,5],
///             vec![0;9],
///         ];
///
///         assert!(matrix_check(&test_example));
///     }
///
///     #[test]
///     fn matrix_check_works_3() {
///         let test_example = vec![
///             vec![1,2,3,4,0,0,7,8,9],
///             vec![0;9],
///             vec![7,8,9,1,2,3,4,5,6],
///             vec![2,3,4,5,6,7,8,9,1],
///             vec![5,6,7,8,9,1,2,3,4],
///             vec![8,9,1,2,3,4,5,6,7],
///             vec![3,4,5,6,7,8,9,1,2],
///             vec![6,7,8,9,1,2,3,4,5],
///             vec![0;9],
///         ];
///
///         assert!(matrix_check(&test_example));
///     }
///
///     #[test]
///     fn matrix_check_works_err() {
///         let test_example = vec![
///             vec![2,2,3,4,5,6,7,8,9],
///             vec![4,5,6,7,8,9,1,2,3],
///             vec![7,8,9,1,2,3,4,5,6],
///             vec![2,3,4,5,6,7,8,9,1],
///             vec![5,6,7,8,9,1,2,3,4],
///             vec![8,9,1,2,3,4,5,6,7],
///             vec![3,4,5,6,7,8,9,1,2],
///             vec![6,7,8,9,1,2,3,4,5],
///             vec![9,1,2,3,4,5,6,7,8],
///         ];
///
///         assert_eq!(matrix_check(&test_example), false);
///     }
///
///     #[test]
///     fn matrix_check_works_err_2() {
///         let test_example = vec![
///             vec![1,2,3,4,5,6,7,8,9],
///             vec![4,5,6,7,8,9,1,5,3],
///             vec![7,8,9,1,2,3,4,5,6],
///             vec![2,3,4,5,6,7,8,9,1],
///             vec![5,6,7,8,9,1,2,3,4],
///             vec![8,9,1,2,3,4,5,6,7],
///             vec![3,4,5,6,7,8,9,1,2],
///             vec![6,7,8,9,1,2,3,4,5],
///             vec![9,1,2,3,4,5,6,7,8],
///         ];
///
///         assert_eq!(matrix_check(&test_example), false);
///     }
/// }
/// ```
Check is the matrix legal
return true if matrix legal
Check is the matrix legal return true if matrix legal
pub fn matrix_check(m: &Vec<Vec<u8>>) -> bool {
        for y in 0..9 { // check row
            let mut checked_value: Vec<u8> = vec![];
            // 直接使用 序列操作符[] 获得的是实际的对象而不是一个reference | pointer | copy
            let row = &m[y];
            row.into_iter()
                .for_each(|&x| {
                    checked_value.push(x);
                });
            checked_value.sort();
            if !&SudokuMatrix::arr_repeat_check(&checked_value) {
                return false;
            }
        }
        for x in 0..9 {
            { // check if there is any duplication of numbers in a column
                let mut checked_value: Vec<u8> = vec![];
                for y in 0..9 { // check column
                    checked_value.push(m[y][x]);
                }
                checked_value.sort();
                if !&SudokuMatrix::arr_repeat_check(&checked_value) {
                    return false;
                }
            }
            { // check 3 x 3 matrix
                // x use to point which matrix
                let mut mm_pos: Vec<(usize, usize)> = vec![];
                let y_range = match x / 3 {
                    0 => 0..3,
                    1 => 3..6,
                    2 => 6..9,
                    _ => panic!("index err"),
                };
                let x_range = match x % 3 {
                    0 => 0..3,
                    1 => 3..6,
                    2 => 6..9,
                    _ => panic!("index err"),
                };
                for y in y_range {
                    for x_inm in x_range.clone() {
                        mm_pos.push((y, x_inm));
                    }
                }
                let mut checked_value: Vec<u8> = vec![];
                mm_pos.into_iter().for_each(|(y, x)| {
                    checked_value.push(m[y][x]);
                });
                checked_value.sort();
                if !&SudokuMatrix::arr_repeat_check(&mut checked_value) {
                    return false;
                }
            }
        }
        true
    }
pub fn matrix_check ( m : & Vec < Vec < u8 > > ) -> bool { for y in 0 .. 9 { // check row let mut checked_value : Vec < u8 > = vec ! [ ] ; // 直接使用 序列操作符[] 获得的是实际的对象而不是一个reference | pointer | copy let row = & m [ y ] ; row . into_iter ( ) . for_each ( | & x | { checked_value . push ( x ) ; } ) ; checked_value . sort ( ) ; if ! & SudokuMatrix :: arr_repeat_check ( & checked_value ) { return false ; } } for x in 0 .. 9 { { // check if there is any duplication of numbers in a column let mut checked_value : Vec < u8 > = vec ! [ ] ; for y in 0 .. 9 { // check column checked_value . push ( m [ y ] [ x ] ) ; } checked_value . sort ( ) ; if ! & SudokuMatrix :: arr_repeat_check ( & checked_value ) { return false ; } } { // check 3 x 3 matrix // x use to point which matrix let mut mm_pos : Vec < ( usize , usize ) > = vec ! [ ] ; let y_range = match x / 3 { 0 => 0 .. 3 , 1 => 3 .. 6 , 2 => 6 .. 9 , _ => panic ! ( " " ) , } ; let x_range = match x % 3 { 0 => 0 .. 3 , 1 => 3 .. 6 , 2 => 6 .. 9 , _ => panic ! ( " " ) , } ; for y in y_range { for x_inm in x_range . clone ( ) { mm_pos . push ( ( y , x_inm ) ) ; } } let mut checked_value : Vec < u8 > = vec ! [ ] ; mm_pos . into_iter ( ) . for_each ( | ( y , x ) | { checked_value . push ( m [ y ] [ x ] ) ; } ) ; checked_value . sort ( ) ; if ! & SudokuMatrix :: arr_repeat_check ( & mut checked_value ) { return false ; } } } true }
Check is the matrix legal
return true if matrix legal
Check is the matrix legal return true if matrix legal
m
&Vec<Vec<u8>>
m
&Vec<Vec<u8>>
examples
None
[cfg(test)]
mod tests {
use super::*.





assert!(matrix_check(&test_example));
}



assert!(matrix_check(&test_example));
}



assert_eq!(matrix_check(&test_example), false);
}



assert_eq!(matrix_check(&test_example), false);
}
}
```
mod tests { use super :: * . assert! ( matrix_check ( &test_example )) ; } assert! ( matrix_check ( &test_example )) ; } assert_eq! ( matrix_check ( &test_example ) false ) ; } assert_eq! ( matrix_check ( &test_example ) false ) ; } } ` ` `