China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

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!

中国DOS联盟论坛
The time now is 2026-06-23 13:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Quiz][Discussion][Sudoku] Three Steps to Solve View 3,682 Replies 20
Floor 16 Posted 2008-08-22 22:57 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Hey, The expert is indeed an expert...

Really impressive.
知,不觉多。不知,乃求知
Floor 17 Posted 2008-08-23 01:55 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
I tested it and found that you made a mistake in calculation. I was still confused that BAT was actually microseconds.

Your time calculation was off by 10,000 times!!!.

1 second = 1000 milliseconds = 1,000,000 microseconds
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 18 Posted 2008-08-24 14:11 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Hope to give a terse explanation of the algorithm, I didn't understand it.
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 19 Posted 2008-08-24 18:13 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
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=


[ Last edited by terse on 2008-8-24 at 09:22 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
everest79 +15 2008-08-25 09:01
简单!简单!再简单!
Floor 20 Posted 2008-08-25 09:02 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 21 Posted 2009-12-26 15:11 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
It's also in milliseconds. It wasn't posted here before

@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
Forum Jump: