You are viewing a single comment's thread. Return to all comments →
def rotange(mat :list): u = mat[0][1] l = mat[1][0] d = mat[2][1] r = mat[1][2] # change angle mat[0][1] = l mat[1][0] = d mat[2][1] = r mat[1][2] = u top_left = mat[0][0] top_right = mat[0][-1] bottom_left = mat[-1][0] bottom_right = mat[-1][-1] # change concer mat[0][0] = bottom_left mat[0][-1] = top_left mat[-1][-1] = top_right mat[-1][0] = bottom_right return mat def row(mat): for i in range(3): mat[i][0],mat[i][-1] = mat[i][-1],mat[i][0] return mat def column(mat): for i in range(3): mat[0][i],mat[-1][i] = mat[-1][i],mat[0][i] return mat def formingMagicSquare(s): magic = [ [[6, 1, 8], [7, 5, 3], [2, 9, 4]], [[8, 1, 6], [3, 5, 7], [4, 9, 2]], [[4, 9, 2], [3, 5, 7], [8, 1, 6]], [[4, 3, 8], [9, 5, 1], [2, 7, 6]], [[2, 7, 6], [9, 5, 1], [4, 3, 8]], [[2, 9, 4], [7, 5, 3], [6, 1, 8]], [[6, 7, 2], [1, 5, 9], [8, 3, 4]], [[8, 3, 4], [1, 5, 9], [6, 7, 2]]] cost = 10e18 for arr in magic: ans = 0 for i in range(3): for j in range(3): ans += abs(arr[i][j] - s[i][j]) print(ans) cost = min(cost,ans) return cost
Seems like cookies are disabled on this browser, please enable them to open this website
Forming a Magic Square
You are viewing a single comment's thread. Return to all comments →