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.
I do like this.
1st. Unroll the input matrix to long list. (imagine the list 9 items was rolled in clockwise direction to create a 3x3 matrix),
2nd. Create the unrolled List of the Magic Square , since magic square can rotate or flip, so the List has some repeat pattern, and I have to create another reverse List.
``List<int> rightRotateList
= new List<int>{8,3,4,9,2,7,6,1,8,3,4,9,2,7,6};
List<int> leftRotateList
= new List<int>(rightRotateList);
leftRotateList.Reverse();
Notice I have exclude the center number of magic square, number 5, since it's unchanged in every version of magic square 3x3.
3rd. Calculate the cost and compare. Here is the full code in C#
Forming a Magic Square
You are viewing a single comment's thread. Return to all comments →
I do like this. 1st. Unroll the input matrix to long list. (imagine the list 9 items was rolled in clockwise direction to create a 3x3 matrix),
2nd. Create the unrolled List of the Magic Square , since magic square can rotate or flip, so the List has some repeat pattern, and I have to create another reverse List.
Notice I have exclude the center number of magic square, number 5, since it's unchanged in every version of magic square 3x3.
3rd. Calculate the cost and compare. Here is the full code in C#
` 4th. It's easier to explain in image, but I don't know how to upload here. So I uploaded to this image hosting service https://ibb.co/sjwBpwZ