Guest User

Untitled

a guest
Jun 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. fn main() {
  2. let mut arr = [[0usize; 9]; 9];
  3.  
  4. for i in 0..81 {
  5. let a = i / 3 % 3; // 000, 111, 222, 000, 111, 222, ...
  6. let x = i % 9; // 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, ...
  7. let b = x % 3; // 012, 012, 012, 012, ...
  8. let c = (b + 1) + 9 * a; // 1, 2, 3, 10, 11, 12, 9, 20, 21, 1, 2, 3, ...
  9. let y = i / 9; // 000000000, 111111111, 222222222, ...
  10. let e = y / 3; // 000000000, 000000000, 000000000, 111111111, 111111111, 111111111, 2222...
  11. let f = c + 3*y + e * 18;
  12.  
  13. arr[x][y] = f;
  14. }
  15.  
  16. for y in 0..9 {
  17. for x in 0..9 {
  18. print!("{:2} ", arr[x][y]);
  19. }
  20. println!();
  21. }
  22.  
  23. println!();
  24.  
  25. // same without array:
  26. for i in 0..81 {
  27. if i % 9 % 9 == 0 { println!(); }
  28. print!("{:2} ", (i % 9 % 3 + 1) + i / 3 % 3 * 9 + 3*(i / 9) + i / 27 * 18)
  29. }
  30. }
Add Comment
Please, Sign In to add comment