Welcome, guest | Sign In | My Account | Store | Cart
:: prime table using rotating multiples stored in environment
@echo off
setlocal enabledelayedexpansion 
mode con cols=90
set @25=-10
set /a num=7,inc1=4,cnt=0,inc2=0,num1=0, maxprime=10000
set lin=    0:
call:line 2 & call:line 3 & call:line 5

:nextnum


if defined @%num% ( 
       for %%i in (!@%num%!) do (
 if %%i lss 0  (set /a num1=%num%-%%i,"inc2=-%%i<<1") else (set /a num1=%num%+%%i,"inc2=-(%%i>>1)")
 call :aux !num1! !inc2!
       )
     set @%num%=
) else (
   call :line %num%
   set /a num1= num * num 
   if %inc1% equ 4 (set/a "inc2=num<<2") else (set /a "inc2=-(num<<1)")
   if !num1! leq %maxprime%   set @!num1!=!inc2! 
)
set /a num+=inc1, inc1=6-inc1
if %num% lss %maxprime% goto nextnum
echo %lin%
pause  & goto:eof

:aux 
 if %1 leq %maxprime%  set @%1=%2 !@%1!
goto:eof   

:line        formats output in 10 right aligned columns
set num2=       %1
set lin=%lin%%num2:~-8%
set /a cnt+=1,res1=(cnt%%10)
if %res1% neq 0 goto:eof
echo %lin% 
set cnt1=    %cnt%
set lin=%cnt1:~-5%:
goto:eof 

Diff to Previous Revision

--- revision 1 2017-04-24 16:26:17
+++ revision 2 2017-04-25 11:43:21
@@ -1,27 +1,42 @@
-setlocal enabledelayedexpansion
+:: prime table using rotating multiples stored in environment
+@echo off
+setlocal enabledelayedexpansion 
+mode con cols=90
+set @25=-10
+set /a num=7,inc1=4,cnt=0,inc2=0,num1=0, maxprime=10000
+set lin=    0:
+call:line 2 & call:line 3 & call:line 5
 
-cls
-echo primes list
-set lin=    0:
-set /a num=1, inc1=4, cnt=0
-call :line 2
-call :line 3
+:nextnum
 
-:nxtcand
-set /a num+=inc1, inc1=6-inc1,div=1, inc2=4
-set /A "x=%num%/(11*1024)+40, x=(%num%/x+x)>>1, x=(%num%/x+x)>>1, x=(%num%/x+x)>>1, x=(%num%/x+x)>>1, x=(%num%/x+x)>>1, x+=(%num%-x*x)>>31,maxdiv=x"
 
-:nxtdiv
-set /a div+=inc2, inc2=6-inc2, res=(num%%div)
-if %div% gtr !maxdiv! call :line %num% &  goto nxtcand
-if %res%  equ 0 (goto :nxtcand ) else ( goto nxtdiv)
+if defined @%num% ( 
+       for %%i in (!@%num%!) do (
+ if %%i lss 0  (set /a num1=%num%-%%i,"inc2=-%%i<<1") else (set /a num1=%num%+%%i,"inc2=-(%%i>>1)")
+ call :aux !num1! !inc2!
+       )
+     set @%num%=
+) else (
+   call :line %num%
+   set /a num1= num * num 
+   if %inc1% equ 4 (set/a "inc2=num<<2") else (set /a "inc2=-(num<<1)")
+   if !num1! leq %maxprime%   set @!num1!=!inc2! 
+)
+set /a num+=inc1, inc1=6-inc1
+if %num% lss %maxprime% goto nextnum
+echo %lin%
+pause  & goto:eof
 
-:line    formats output in 10 right aligned columns
-set num1=      %1
-set lin=!lin!%num1:~-7%
+:aux 
+ if %1 leq %maxprime%  set @%1=%2 !@%1!
+goto:eof   
+
+:line        formats output in 10 right aligned columns
+set num2=       %1
+set lin=%lin%%num2:~-8%
 set /a cnt+=1,res1=(cnt%%10)
 if %res1% neq 0 goto:eof
 echo %lin% 
-set cnt1=    !cnt!
-set lin=!cnt1:~-5!:
+set cnt1=    %cnt%
+set lin=%cnt1:~-5%:
 goto:eof 

History