• + 0 comments

    Meanwhile, I'm sitting here failing to read the full prompt and trying to come up with a solution where I can find the cost of getting the magic matrix for any arbitrary n hahaha. Started myself thinking about how the magic matrix always has left and right eigenvector (1,..,1) meaning that X1 = s1 and X^T1 = s1 for some integer s in [1,n] and the cost is essentially the 1-norm of the difference ||X-A||. Turns out we can reframe the problem as min{X \in {1,..,n}^{nxn}} ||X-A|| s.t. X1 = X^T1 = trace(X)1 = trace(X\cdot J)1 \in {1, ..., n^2}, where J_{i,j} = 0 for i != n-j and J_{i,n-i} = 1. Using the new target sum_i sum_j Z_{i,j} with the contraints Z_{i,j} >= X_{i,j} - A_{i,j}, Z_{i,j} >= A_{i,j} - A_{i,j} and Z_{i,j} >= 0 we can come up with a pretty doable optimization problem up to n=10 I think.