We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Forming a Magic Square
Forming a Magic Square
Sort by
recency
|
1248 Discussions
|
Please Login in order to post a comment
Java 8 Code
public static int formingMagicSquare(List> s) { // Write your code here // mid[1][1]=5, total= 45,col=15,row=15. int cost[]={0,0,0,0,0,0,0,0}; int t[][]={ {2,9,4,7,5,3,6,1,8}, {4,9,2,3,5,7,8,1,6}, {4,3,8,9,5,1,2,7,6}, {8,3,4,1,5,9,6,7,2}, {6,7,2,1,5,9,8,3,4}, {2,7,6,9,5,1,4,3,8}, {6,1,8,7,5,3,2,9,4}, {8,1,6,3,5,7,4,9,2}, };
for(int i=0;i<8;i++){ cost[i]= Math.abs(t[i][0]-s.get(0).get(0))+Math.abs(t[i][1] -s.get(0).get(1))+Math.abs(t[i][2]-s.get(0).get(2));
My JavaScript Solution
My Javascript Solution:
}