| 
 
ccwan 
金牌会员
 
      
 
  
 
积分 2725 
发帖 1160 
注册 2006-9-23 来自 河北廊坊 
状态 离线
 | 
『楼 主』:
 用批处理如何显示动态变换的九宫格?
 
使用 LLM 解释/回答一下
  
相信很多人都知道九宫格吧, 
 
戴九履一,左三右七,二四为肩,六八为足,横竖斜三个数相加都得15 
突发奇想,可不可以用批处理来显示九宫格呢?可不是简单的echo哦。 
要列出九宫格局,每个格中一个数字,每隔几秒钟变换格中的数字,例如:
 九宫            
 4  9  2 
3  5  7 
8  1  6 
 
变成 
2  9  4 
7  5  3 
6  1  8 
 
又变成 
6  1  8 
7  5  3 
2  9  4 
 
又变成 
8  1  6 
3  5  7 
4  9  2 
 
又变成 
6  7  2 
1  5  9 
8  3  4 
 
又变成 
8  3  4 
1  5  9 
6  7  2 
 
等等等等,要求列举所有可能,记住不是罗列,每次显示一种。 
 
 Last edited by ccwan on 2007-1-14 at 01:31 AM ]  
I believe many people know the magic square. 
 
Nine in the top, one in the bottom, three on the left, seven on the right, two and four on the shoulders, six and eight on the feet, and the sum of three numbers in horizontal, vertical, and diagonal directions is all 15.
 
Suddenly I thought, can we use batch processing to display the magic square? It's not just a simple echo.
 
We need to list the magic square pattern, with one number in each grid, and the numbers in the grids change every few seconds. For example:
 Magic square            
 4  9  2 
3  5  7 
8  1  6 
 
Change to 
2  9  4 
7  5  3 
6  1  8 
 
Then change to 
6  1  8 
7  5  3 
2  9  4 
 
Then change to 
8  1  6 
3  5  7 
4  9  2 
 
Then change to 
6  7  2 
1  5  9 
8  3  4 
 
Then change to 
8  3  4 
1  5  9 
6  7  2 
 
And so on. The requirement is to list all possibilities. Remember it's not just listing, but showing one kind each time. 
 
 Last edited by ccwan on 2007-1-14 at 01:31 AM ]  
    
 
  
  |  
                  
  
                    三人行,必有吾师焉。   学然后知不足,教然后知困,然后能自强也。 |   
 | 
  2007-1-14 01:29 | 
  
 | 
 | 
 
everest79 
金牌会员
 
       一叶枝头,万树皆春
  
  
积分 2564 
发帖 1127 
注册 2006-12-25 
状态 离线
 | 
『第 2 楼』:
 
 
使用 LLM 解释/回答一下
  
2 4 6 8 
1 3 7 9 
5 
河图格式是规定的 
2 4 6 8 
1 3 7 9 
5 
The format of the River Chart is prescribed 
    
 
  
 |   
 | 
  2007-1-14 01:40 | 
  
 | 
 | 
 
ccwan 
金牌会员
 
      
 
  
 
积分 2725 
发帖 1160 
注册 2006-9-23 来自 河北廊坊 
状态 离线
 | 
『第 3 楼』:
 
 
使用 LLM 解释/回答一下
  
并非讨论河图洛书,只要达到一楼的要求。 
It's not about discussing the River Chart and Luo Book, just meet the requirements of the first floor. 
    
 
  
  |  
                  
  
                    三人行,必有吾师焉。   学然后知不足,教然后知困,然后能自强也。 |   
 | 
  2007-1-14 01:43 | 
  
 | 
 | 
 
everest79 
金牌会员
 
       一叶枝头,万树皆春
  
  
积分 2564 
发帖 1127 
注册 2006-12-25 
状态 离线
 | 
『第 4 楼』:
 
 
使用 LLM 解释/回答一下
  
九宫八卦,很明显呀,只有八个结果 
Nine palaces and eight trigrams, it's obvious that there are only eight results 
    
 
  
 |   
 | 
  2007-1-14 02:14 | 
  
 | 
 | 
 
vkill 
金牌会员
 
      
 
  
  
积分 4103 
发帖 1744 
注册 2006-1-20 来自 甘肃.临泽 
状态 离线
 | 
 | 
  2007-1-14 03:08 | 
  
 | 
 | 
 
9527 
银牌会员
 
      努力做坏人
  
 
积分 1185 
发帖 438 
注册 2006-8-28 来自 北京 
状态 离线
 | 
『第 6 楼』:
 
 
使用 LLM 解释/回答一下
  
这个难度确实大,不好找规律 
This difficulty is indeed great, it's not easy to find the pattern 
    
 
  
  |  
                  
  
                    我今后在论坛的目标就是做个超级坏人!!! |   
 | 
  2007-1-14 03:50 | 
  
 | 
 | 
 
namejm 
荣誉版主
 
        batch fan
  
 
积分 5226 
发帖 1737 
注册 2006-3-10 来自 成都 
状态 离线
 | 
 | 
  2007-1-14 05:23 | 
  
 | 
 | 
 
vkill 
金牌会员
 
      
 
  
  
积分 4103 
发帖 1744 
注册 2006-1-20 来自 甘肃.临泽 
状态 离线
 | 
 | 
  2007-1-14 05:27 | 
  
 | 
 | 
 
lxmxn 
版主
 
        
 
  
 
积分 11386 
发帖 4938 
注册 2006-7-23 
状态 离线
 | 
『第 9 楼』:
 
 
使用 LLM 解释/回答一下
  
 
  版主实在厉害啊,PF。 
 
  The moderator is really amazing, PF. 
 
    
 
  
 |   
 | 
  2007-1-14 05:30 | 
  
 | 
 | 
 
jy1260662 
初级用户
 
  
 
  
  
积分 22 
发帖 9 
注册 2007-1-14 来自 珠海 
状态 离线
 | 
『第 10 楼』:
 
 
使用 LLM 解释/回答一下
  
Originally posted by lxmxn at 2007-1-13 04:30 PM: 
 
  版主实在厉害啊,PF。  
同感!~~  
Originally posted by lxmxn at 2007-1-13 04:30 PM: 
 
  The moderator is really amazing, PF.  
I feel the same!~~  
    
 
  
 |   
 | 
  2007-1-14 08:56 | 
  
 | 
 | 
 
pengfei 
银牌会员
 
     
 
  
 
积分 1218 
发帖 485 
注册 2006-7-21 来自 湖南.娄底 
状态 离线
 | 
   『第 11 楼』:
 
 
使用 LLM 解释/回答一下
  
namejm兄的代码甚为精彩~~~!这里九宫格指的是魔方阵, 楼主给出的九宫格为三阶的魔方阵, 而变换时只是以纵横为中心轴将其两侧的阵列互换了一下, 它的行、列及对角都是相同数字相加。 
大家还可以扩展一下, 把阶数扩大为5或7等.
  
所谓魔方阵是指这样的方阵,它的每一行、每一列和对角线之和均相等。如下是三阶魔方阵: 
 
8  1  6 
3  5  7 
4  9  2 
 
 
打印魔方阵算法: 
 
1、将1放在第一行中间一列; 
 
2、从2开始直到n*n止各数依次按下列规则存放;每一个数存放的行比前一个数的行数减1,列数加1. 例如上面的三阶魔方阵,5在4的上一行后一列; 
 
3、如果上一个数的行数为1,则下一个数的行数为n(指最下一行). 例如: 1在第1行,则2应放在最下一行,列数同样加1; 
 
4、当上一个数的列数为n时,下一个数的列数应为1,行数减1. 例如: 2在第3行最后一列,则3应放在第2行第1列; 
 
5、如果按上面规则确定的位置上已有数,或上一个数是第1行第n列时,则把下一个数放在上一个数的下面. 例如: 按上面的规定,4应该放在第1行第2列,但该位置已被1占据,所以4就放在3的下面.由于6是第1行第3列(即最后一列),故7放在6下面.按此方法可以得到任何阶的魔方阵. 
 
 
根据上面的算法用批处理实现打印魔方阵完全可以实现, 可能需要构建二维数组。
 
发个我以前写的打印魔方阵的小程序。
 
 Last edited by pengfei on 2007-1-15 at 01:29 AM ]  
Brother namejm's code is extremely wonderful~~~! Here the nine-square grid refers to a magic square. The nine-square grid given by the original poster is a 3x3 magic square. When transforming, it just swaps the arrays on both sides with the horizontal and vertical centers as the axis. The sums of its rows, columns, and diagonals are all the same numbers added together. 
You can also expand it and increase the order to 5 or 7, etc.
  
A magic square is a square array in which the sum of each row, each column, and the diagonal are all equal. The following is a 3x3 magic square: 
 
8  1  6 
3  5  7 
4  9  2 
 
 
Algorithm for printing a magic square: 
 
1. Place 1 in the middle column of the first row; 
 
2. For each number from 2 to n*n, place each number according to the following rule: The row of each number is 1 less than the row of the previous number, and the column number is 1 more. For example, in the above 3x3 magic square, 5 is in the row above and column to the right of 4; 
 
3. If the row of the previous number is 1, then the row of the next number is n (referring to the bottom row). For example: 1 is in the 1st row, then 2 should be placed in the bottom row, and the column number is also increased by 1; 
 
4. When the column number of the previous number is n, the column number of the next number should be 1, and the row number is decreased by 1. For example: 2 is in the last column of the 3rd row, then 3 should be placed in the 2nd row and 1st column; 
 
5. If the position determined by the above rule already has a number, or the previous number is in the 1st row and nth column, then place the next number below the previous number. For example: According to the above regulations, 4 should be placed in the 1st row and 2nd column, but this position is already occupied by 1, so 4 is placed below 3. Since 6 is in the 1st row and 3rd column (i.e., the last column), 7 is placed below 6. In this way, you can get a magic square of any order. 
 
 
According to the above algorithm, it is completely feasible to implement printing a magic square with batch processing. Probably need to construct a two-dimensional array.
 
Send a small program I wrote before to print a magic square.
 
 Last edited by pengfei on 2007-1-15 at 01:29 AM ]  
    
 
     此帖被 +10 点积分          点击查看详情    | 评分人:【 lxmxn 】 | 分数: +10 |   时间:2007-1-14 15:12 |  
  |   
 
 
  
附件
1:   sigil.rar (2007-1-14 13:35, 4.22 KiB, 下载附件所需积分 1 点
,下载次数: 83)
 
 
  |  
                  
  
                    业精于勤而荒于嬉,形成于思而毁于随。 |   
 | 
  2007-1-14 13:25 | 
  
 | 
 | 
 
lxmxn 
版主
 
        
 
  
 
积分 11386 
发帖 4938 
注册 2006-7-23 
状态 离线
 | 
『第 12 楼』:
 
 
使用 LLM 解释/回答一下
  
 
  To pengfei : 
 
  兄写的小程序也精彩啊,而且把其中的算法也说的很明白,精彩。 
 
  To pengfei : 
 
  The small program you wrote is also wonderful, and you have explained the algorithm in it very clearly, wonderful. 
 
    
 
  
 |   
 | 
  2007-1-14 15:14 | 
  
 | 
 | 
 
ccwan 
金牌会员
 
      
 
  
 
积分 2725 
发帖 1160 
注册 2006-9-23 来自 河北廊坊 
状态 离线
 | 
『第 13 楼』:
 
 
使用 LLM 解释/回答一下
  
namejm的水平真不是盖的,佩服得很啊! 
The level of namejm is really remarkable, I admire it a lot! 
    
 
  
  |  
                  
  
                    三人行,必有吾师焉。   学然后知不足,教然后知困,然后能自强也。 |   
 | 
  2007-1-14 21:02 | 
  
 | 
 | 
 
chainliq 
高级用户
 
     学无尽止
  
 
积分 635 
发帖 244 
注册 2006-4-15 来自 广西贵港 
状态 离线
 | 
 | 
  2007-1-15 01:20 | 
  
 | 
 | 
 
everest79 
金牌会员
 
       一叶枝头,万树皆春
  
  
积分 2564 
发帖 1127 
注册 2006-12-25 
状态 离线
 | 
     『第 15 楼』:
 
 
使用 LLM 解释/回答一下
  
 
@ECHO OFF 
:TOP 
SET /A R=%RANDOM%%%8 
SET /A R=%R%+%R%%%2 
IF %R% LEQ 0 GOTO TOP 
IF 0x00%R% EQU 0x00%A% ( 
SET Ct=1) ELSE ( 
SET Ct=0) 
SET A=%R% 
SET /A E=5 
SET /A At=15-%A% 
SET /A I=%At%-%E% 
SET /A It=15-%I% 
SET /A X=15-%A%*2-%E% 
IF %X% LEQ 0 SET /A X=~%X%+1 
SET /A Y=20-%A%-%X%-%I% 
IF %Ct% EQU 0 (SET /A C=%X%,G=%Y%) ELSE SET /A C=%Y%,G=%X%  
SET /A B=%At%-%C%,D=%At%-%G%,F=%It%-%C%,H=%It%-%G% 
 
ECHO %A% %B% %C% 
ECHO %D% %E% %F% 
ECHO %G% %H% %I% 
pause>nul 
cls&&goto top 
 
我也试着写了一个,反推出来的  
``` 
@ECHO OFF 
:TOP 
SET /A R=%RANDOM%%%8 
SET /A R=%R%+%R%%%2 
IF %R% LEQ 0 GOTO TOP 
IF 0x00%R% EQU 0x00%A% ( 
SET Ct=1) ELSE ( 
SET Ct=0) 
SET A=%R% 
SET /A E=5 
SET /A At=15-%A% 
SET /A I=%At%-%E% 
SET /A It=15-%I% 
SET /A X=15-%A%*2-%E% 
IF %X% LEQ 0 SET /A X=~%X%+1 
SET /A Y=20-%A%-%X%-%I% 
IF %Ct% EQU 0 (SET /A C=%X%,G=%Y%) ELSE SET /A C=%Y%,G=%X%  
SET /A B=%At%-%C%,D=%At%-%G%,F=%It%-%C%,H=%It%-%G% 
 
ECHO %A% %B% %C% 
ECHO %D% %E% %F% 
ECHO %G% %H% %I% 
pause>nul 
cls&&goto top 
``` 
    
 
 
 
  
 |   
 | 
  2007-1-15 08:12 | 
  
 |