1. Re: Primes
- Posted by Arthur Adamson <euclid at ISOC.NET> Mar 06, 1998
- 477 views
Carl, >Carl, > >Here is my version of a prime number generator. Originally copied from a >magazine in the early 80's, and optimized on my then TI-99/4A. It is written >a little different than yours and on or both of the programs may need some >modification for a true speed test. > >I've documented it as much as I can. Hope this is useful. > >Mike Dickey > > >-- Filename > prime.ex >-- Generate prime numbers below h (less than 100000, formatted output) >-- By Michael Dickey > >integer h, l, f >atom t1, t2 > >h = 10000 -- enter your upper limit here > >t1 = time() -- start time > >for x = 1 to h by 2 do -- test every odd # from 1 to h >l = 0 -- control variable >f = floor( sqrt( x )) -- define y loop limit > for y = 3 to f by 2 do -- test every odd # 3 -> f > if remainder(x, y) = 0 then -- all prime #'s will have a remainder > l = 1 -- set if x is not prime > exit -- exit y loop, goto next x > end if > end for -- exit y loop normally, x is prime > if l = 0 then -- skip if not prime > printf (1, "%5d \t", x) -- print all x's that are prime > end if >end for > >t2 = time() - t1 -- execution time >printf(1, "\n Run Time = %2.2f", t2) > Arthur P. Adamson, The Engine Man, euclid at isoc.net