home *** CD-ROM | disk | FTP | other *** search
- *REM This batch file is Freeware, free to use and redistribute unmodified *
- *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
-
- goto alku
- :W
- set peek=2^set try=%@eval[%try+2+(%try+1)%%3+%@int[%@eval[1/((%try+2+(%try+1)%%3)%%5+1)]]*((%try+1)%%5)]^if %try gt %limit goto end
- :L
- set peek=%@eval[%peek+1]^if %@eval[%[try]%%%[%peek]]==0 goto W^if %@eval[(%[%peek]+2)*(%[%peek]+2)] le %try goto L^iff %@eval[%_column+%@len[%try]+2] le 80 then^if %_column != 0 echos ` `^else^echo.^endiff^screen %_row %_column %try,^goto W
-
- REM Calculate Prime Numbers using modified "Sieve of Eratosthenes"
- REM Timestamp 15-Nov-1992
-
- REM why I'm doing all this jumping? Well, it's called speed optimization
- REM Basically ":W" above is same as ":work" below and equally ":L" and ":loop"
- REM They are placed in the beginning to be located as fast as possible (?)
-
- :alku
- break on^setlocal^unalias *^unset *^if %# gt 0 goto error
-
- REM set up the working environment and defaults..
- set limit=11111111^set index=4^set 1=2^set 2=3^set 3=5^set 4=7^set try=7
-
- REM Here are 3 separate outputs: comma-separated, space separated and columns.
- REM To change output change 3 places: below the startup, in :loop and in :L.
- REM Note: one (1) is not a prime number.
-
- echos 2, 3, 5, 7,
- REM echos 2 3 5 7
- REM echos 2 3 5 7
-
- :work
- REM save time and check only some numbers..
- REM 2 is a prime number, so I don't have to check numbers dividable by 2
- REM 3 is a prime number, so I don't have to check numbers dividable by 3
- REM 5 is a prime number, so I don't have to check numbers dividable by 5
- set peek=3^set try=%@eval[%try+2+(%try+1)%%3+%@int[%@eval[1/((%try+2+(%try+1)%%3)%%5+1)]]*((%try+1)%%5)]
-
- :loop
- set peek=%@eval[%peek+1]^if %@eval[%[try]%%%[%peek]]==0 goto work
-
- REM don't have to check against every prime number already found..
- if %@eval[(%[%peek]+2)*(%[%peek]+2)] le %try goto loop
-
- REM "1229" took 9 bytes Environmental Memory, 15 enough for at least 6digits
- iff %_env gt 15 then^set index=%@eval[%index+1]^set %index=%try
- else^set limit=%@eval[%try*%try]^endiff
-
- REM current place + space + number + comma equal max 80 characters on line.
- REM Note: "n" is NEWLINE _except_ with "echos n" it's LINEFEED, watch out.
- REM IMHO a character should have only one definition, not two. Weird.
- REM 4DOS 4.01 rev D
-
- iff %@eval[%_column+%@len[%try]+2] le 80 then^if %_column != 0 echos ` `
- else^echo.^endiff^screen %_row %_column %try,
-
- REM Listing without commas; to use this comment 2 previous lines etc.
- REM iff %@eval[%_column+%@len[%try]+1] le 80 then^if %_column != 0 echos ` `
- REM else^echos rn^endiff^screen %_row %_column %try
-
- REM If you prefer columns.. you need to fix echoing of 2,3,5,7
- REM also fix the output of the later part of this batch file (:L)
- REM if %@eval[%_column+8] gt 80 echos nr
- REM screen %_row %@eval[%_column+8-%@len[%try]] %try
-
- if %limit==11111111 goto work
-
- REM All Env Memory is used up, now go and calculate, what u can w/primes u got
- goto W
-
- :error
- echo Usage: %@lower[%@name[%0]]^echo.
-
- :end
- break off^quit
-
- REM Now this one was fun to write! BTW: did u notice I used full 80 columns
- REM not just the usual 79 ... B-)
-