Hey, The expert is indeed an expert...
Really impressive.
Really impressive.
知,不觉多。不知,乃求知
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
Originally posted by everest79 at 2008-8-24 14:11:
Hope terse explains the algorithm, I didn't understand
@echo off&setlocal enabledelayedexpansion
:st
rem call 9 times %1-%9 that is lines 1-9
for /l %%i in (1 1 9) do call:lp %%i
pause&exit
:lp
rem get 1-9 random numbers per line
for /l %%i in (1 1 9) do set .!random!!random!!random!=%%i
for /f "tokens=1,2 delims==" %%i in ('set .') do set str=%%j !str!&set %%i=
rem clear variables in the line where %1 is located when returning to the IP tag in case of error
for /l %%i in (1 1 9) do set %1%%i=
rem set column n (starts at 1) v previous line value %1-1 y-z start column range value x start row value variable a judge whether it is line 1 4 7
set var=%str%&set/a n=1,v=%1-1,y=1,z=3,x=1,a=%1%%3
rem set x (row number) according to %1 range value
if %1 geq 4 if %1 leq 6 (set/a x=4) else set/a x=7
:lp0
rem set y-z column range value according to variable column value n
if %n% geq 4 if %n% leq 6 (set/a y=4,z=6) else set/a y=7,z=9
for %%a in (!var!) do (
rem if the same in the same line, clear and return to lp0
if defined .%%a set var=!var:%%a=!&goto lp0
rem judge whether the same column appeared before in %1 line
for /l %%i in (1 1 %1) do if %%a equ !%%i%n%! set var=!var:%%a=!&goto lp0
rem judge whether %1 line is line 1 4 7 by variable a and judge whether it appeared in y-z column of x-v lines
if %a% neq 1 (for /l %%j in (%x% 1 %v%) do (
for /l %%k in (%y% 1 %z%) do if %%a equ !%%j%%k! set var=!var:%%a=!&goto lp0
))
set %1!n!=%%a&set .%%a=a
rem loop 1-9 columns
if !n! lss 9 set/a n+=1&set var=!str:%%a=!&goto lp0
)
rem clear variables
set str=&set n=
for /l %%i in (1 1 9) do set .%%i=
rem judge whether 9 columns are obtained, set to restart after 30 times of error
if "!%19!"=="" set/a mn+=1&if !mn! gtr 30 (set mn=&cls&goto st)else goto lp
for /l %%i in (1 1 9) do set .%%i=&set/p=!%1%%i! <nul
echo.&set mn=
| Rater | Score | Time |
|---|---|---|
| everest79 | +15 | 2008-08-25 09:01 |
@echo off &setlocal enabledelayedexpansion
:test
set "numx=123456789"
set "ca=call :next"
:first
set /a ra=%random%%%9+1,rb=%random%%%9+1
set numx=!numx:%ra%=x!
set numx=!numx:%rb%=%ra%!
set numx=!numx:x=%rb%!
if %ra% neq 9 (goto :first)
set h1=%numx%
%ca% 1 2
%ca% 2 3
set h4=%h1:~2,1%%h1:~0,2%%h1:~5,1%%h1:~3,2%%h1:~8,1%%h1:~6,2%
%ca% 4 5
%ca% 5 6
set h7=%h4:~2,1%%h4:~0,2%%h4:~5,1%%h4:~3,2%%h4:~8,1%%h4:~6,2%
%ca% 7 8
%ca% 8 9
for /l %%a in (1,1,9) do (for /l %%b in (1,1,9) do (set h%%a=!h%%a:%%b=%%b !))
for /l %%a in (1,1,9) do (echo,!h%%a!)
echo, &pause &echo,
goto :test
:next
set h%2=!h%1:~3,3!!h%1:~6!!h%1:~0,3!
goto :eof