中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 14:58
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » How to display a dynamically changing nine-grid using batch processing?
Printable Version  6,420 / 31
Floor1 ccwan Posted 2007-01-14 01:29
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
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:



[ Last edited by ccwan on 2007-1-14 at 01:31 AM ]
Floor2 everest79 Posted 2007-01-14 01:40
金牌会员 Posts 1,127 Credits 2,564
2 4 6 8
1 3 7 9
5
The format of the River Chart is prescribed
Floor3 ccwan Posted 2007-01-14 01:43
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
It's not about discussing the River Chart and Luo Book, just meet the requirements of the first floor.
Floor4 everest79 Posted 2007-01-14 02:14
金牌会员 Posts 1,127 Credits 2,564
Nine palaces and eight trigrams, it's obvious that there are only eight results
Floor5 vkill Posted 2007-01-14 03:08
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
This is difficult.
Floor6 9527 Posted 2007-01-14 03:50
银牌会员 Posts 438 Credits 1,185 From 北京
This difficulty is indeed great, it's not easy to find the pattern
Floor7 namejm Posted 2007-01-14 05:23
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The demonstration code is as follows:

There was a misspelled English word, corrected it: (By the way, the display interface was beautified.

[ Last edited by namejm on 2007-1-13 at 05:38 PM ]
Floor8 vkill Posted 2007-01-14 05:27
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Floor9 lxmxn Posted 2007-01-14 05:30
版主 Posts 4,938 Credits 11,386

  The moderator is really amazing, PF.
Floor10 jy1260662 Posted 2007-01-14 08:56
初级用户 Posts 9 Credits 22 From 珠海
Originally posted by lxmxn at 2007-1-13 04:30 PM:

  The moderator is really amazing, PF.

I feel the same!~~
Floor11 pengfei Posted 2007-01-14 13:25
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
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.



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 ]

Attachments
sigil.rar (4.22 KiB)
Floor12 lxmxn Posted 2007-01-14 15:14
版主 Posts 4,938 Credits 11,386

  To pengfei :

  The small program you wrote is also wonderful, and you have explained the algorithm in it very clearly, wonderful.
Floor13 ccwan Posted 2007-01-14 21:02
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
The level of namejm is really remarkable, I admire it a lot!
Floor14 chainliq Posted 2007-01-15 01:20
高级用户 Posts 244 Credits 635 From 广西贵港
Master, KOOL````````
Floor15 everest79 Posted 2007-01-15 08:12
金牌会员 Posts 1,127 Credits 2,564
```
@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
```
1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023