You are viewing a single comment's thread. Return to all comments →
Big Brain Question
def formingMagicSquare(s): lu_1 = [[8,1,6], [3,5,7], [4,9,2]] lu_2 = [[6,1,8], [7,5,3], [2,9,4]] lu_3 = [[4,9,2], [3,5,7], [8,1,6]] lu_4 = [[2,9,4], [7,5,3], [6,1,8]] lu_5 = [[8,3,4], [1,5,9], [6,7,2]] lu_6 = [[4,3,8], [9,5,1], [2,7,6]] lu_7 = [[6,7,2], [1,5,9], [8,3,4]] lu_8 = [[2,7,6], [9,5,1], [4,3,8]] var = [ lu_1, lu_2, lu_3, lu_4, lu_5, lu_6, lu_7, lu_8 ] diff = [] for v in var: temp = 0 for v_, s_ in zip(v, s): for v__, s__ in zip(v_, s_): if v__ != s__: temp += abs(v__ - s__) diff.append(temp) diff = sorted(diff) return diff[0]
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 →
Big Brain Question