Actually, I didn't test it. Analyzing from the algorithm, I know that without testing, the time is the same. It's just that the variables used are different. The triple loop might be slightly more time-consuming theoretically.
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 plp626 at 2008-4-12 23:20:
Actually, I didn't test it. From an algorithm analysis, I knew that without testing, the time would be the same. It's just that different variables are used. The three - layer loop might theoretically take a little more time.
@echo off
:: Code one
for /l %%a in (10000 1 99999) do echo %%a
:: Code two
for /l %%a in (1 1 9) do (
for /l %%b in (0 1 9) do (
for /l %%c in (0 1 9) do (
for /l %%d in (0 1 9) do (
for /l %%e in (0 1 9) do (
echo %%a%%b%%c%%d%%d
)))))
pause
@echo off
setlocal enabledelayedexpansion
for /l %%i in (100,1,999) do (
set str=%%i
set/a a=!str:~,1!, b=!str:~1,1!, c=!str:~2,1!
set /a var=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !var! equ !str! echo !str!
)
pause
@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do for /l %%j in (0,1,9) do for /l %%k in (0,1,9) do (
set/a a=%%i,b=%%j,c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
pause
Originally posted by 26933062 at 2008-4-13 03:01:
I really don't know which algorithm for set is faster.
Do the following two codes have different efficiencies? I thought code one should be faster?
:
@echo off
:: Code One
for /l %%a in (10000 ...