摘要
用3种不同的构造法可以生成奇阶、单偶阶和双偶阶三类不同的幻方。以全排列为基础,可以求出全部8个三阶幻方。为了求出全部四阶幻方,先找出1至16中和为34的四个数字组合,共有2064组。该文提出了两个求解全部四阶幻方的算法。算法一先确定一列,再确定4行。算法二先确定两列,再确定4行。四阶幻方共有7040个,其中880个无重复。算法二比算法一效率高得多,表明增加循环之前的检验之后,程序运行的速度大大提高了。
Three different methods are used to structure three different kinds of magic squares in this paper: odd order, single-even order and doubly even order. Based on full permutation, All the third-order magic square are found, a total of 8. In order to get all the fourth-order magic square, firstly, identify the group containing 4 elements the sum of which is 34. There are 2064 such groups. This paper provides two algorithms to calculate all the fourth-order magic squares. Algorithm I first determine one column, and then determines the four ranks. Algorithm II first determines two columns, and then determines the four ranks. There are 7040 fourth-order magic squares, in which no-repeat of 880. Algorithm II is far more efficient than Algorithm I, which indicates that the increase of the checks before the cycles contributes to the promotion of the program’s operating speed.
出处
《微型电脑应用》
2010年第1期17-18,4,共2页
Microcomputer Applications
关键词
四阶幻方
构造法
全部解
无重复解
Fourth-order Magic Squares
Structure Method
All Solutions
No-repeat Solutions