Advertisement
AlexG2230954

Untitled

Apr 12th, 2024
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. def reverse_rows(n):
  2.     for i in range(n // 2):
  3.         for j in range(n):
  4.             yield (i, j), (n - 1 - i, j)
  5.  
  6.  
  7. def print_matrix(m):
  8.     for row in m:
  9.         print(row)
  10.  
  11.  
  12. def apply_swaps(matrix, swaps) -> None:
  13.     for (i1, j1), (i2, j2) in swaps:
  14.         matrix[i1][j1], matrix[i2][j2] = matrix[i2][j2], matrix[i1][j1]
  15.  
  16.  
  17. def test_works():
  18.     A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  19.     print_matrix(A)
  20.     print()
  21.     apply_swaps(A, reverse_rows(3))
  22.     print_matrix(A)
  23.  
  24.  
  25. def main():
  26.     n = int(input('n: '))
  27.     for t1, t2 in reverse_rows(n):
  28.         print(*t1, *t2)
  29.  
  30.  
  31. main()
Tags: random-shit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement