kxcoze

satie_mak_lab_2

Apr 21st, 2021
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. from random import randint
  2.  
  3. import numpy as np
  4.  
  5.  
  6. n = int(input("Введите размерность матрицы: "))
  7.  
  8. matrix = np.array([[randint(-30, 30) for x in range(n)] for y in range(n)])
  9.  
  10. print(matrix)
  11.  
  12. start_comb = []
  13. for i in range(1, n):
  14.     init_comb = []
  15.     start = 0
  16.     for j in range(i, n):
  17.         init_comb.append((start, j))
  18.         start += 1
  19.     start_comb.append(init_comb.copy())
  20.  
  21. starting_comb = [[x[::-1] for x in y] for y in start_comb][::-1] + start_comb
  22. # print(starting_comb)
  23.  
  24. sums = []
  25. for combs in starting_comb:
  26.     sum = 0
  27.     for comb in combs:
  28.         sum += matrix[comb[0]][comb[1]]
  29.     sums.append(sum)
  30. print(sums)
  31.  
  32. print(max(sums))
Advertisement
Add Comment
Please, Sign In to add comment