Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let mut arr = [[0usize; 9]; 9];
- for i in 0..81 {
- let a = i / 3 % 3; // 000, 111, 222, 000, 111, 222, ...
- let x = i % 9; // 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, ...
- let b = x % 3; // 012, 012, 012, 012, ...
- let c = (b + 1) + 9 * a; // 1, 2, 3, 10, 11, 12, 9, 20, 21, 1, 2, 3, ...
- let y = i / 9; // 000000000, 111111111, 222222222, ...
- let e = y / 3; // 000000000, 000000000, 000000000, 111111111, 111111111, 111111111, 2222...
- let f = c + 3*y + e * 18;
- arr[x][y] = f;
- }
- for y in 0..9 {
- for x in 0..9 {
- print!("{:2} ", arr[x][y]);
- }
- println!();
- }
- println!();
- // same without array:
- for i in 0..81 {
- if i % 9 % 9 == 0 { println!(); }
- print!("{:2} ", (i % 9 % 3 + 1) + i / 3 % 3 * 9 + 3*(i / 9) + i / 27 * 18)
- }
- }
Add Comment
Please, Sign In to add comment