✔ 最佳答案
Right or Write ? XDDDD
The most simple way is to use permutations and try-and-error:
- generate all permutations from the numbers you want.
- for each permutation :
- place them in square and test whether it is a magic square
- if it is, return that permutation.
However, there exists more intelligent methods to do it, you can check them in the wiki.