sidorenkov

3_matrix

Jun 21st, 2020
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. def print_matrix(matrix):
  4.     for row in matrix:
  5.         for x in row:
  6.             print(x, end = " ")
  7.         print()
  8.  
  9. def create_matrix():
  10.     unique_nums = [_ for _ in range(1, 10)]
  11.     random.shuffle(unique_nums)
  12.     matrix = [unique_nums[n : n + 3] for n in range (0, 9, 3)]
  13.     return matrix
  14.  
  15. def creat_matrix_list(count):
  16.     matrix_list = []
  17.     for _ in range(0, count):
  18.         matrix = create_matrix()
  19.         matrix_list.append(matrix)
  20.     return matrix_list
  21.  
  22. def compute_unique_sum(matrix_list):
  23.     unique_sum = set()
  24.     n = 0
  25.     for matrix in matrix_list:
  26.         print(f"Matrix [{n}]: ")
  27.         n += 1
  28.         print_matrix(matrix)
  29.         for row in matrix:
  30.             row_sum = 0
  31.             row_sum += sum(row)
  32.             print(row_sum)
  33.             unique_sum.add(row_sum)
  34.     return unique_sum
  35.  
  36. MATRIX_COUNT = 30
  37. matrix_list = creat_matrix_list(MATRIX_COUNT)
  38. unique_sum = compute_unique_sum(matrix_list)
  39. print(unique_sum)
RAW Paste Data