Sieve of Eratosthenes
Jay Schille
jayschille at gmail.com
Tue Jun 30 21:40:14 PDT 2009
> >The Sieve cries out for a progress bar. So I created two Flash Art
>>superobjects, named them "Background" and "Slider" and overlaid them
>>on the Display form, then inserted the code:
>>progressbar "Background", "Slider", import(), nmax
>>after the line chunkfilter 4, PNumbers, PNumbers, ?(
>>(binaryvalue(import()) mod P) = 0,"",import()).
>>
>>But when I ran the procedure, Panorama crashed.
>>
>>I realize the progress bar will probably slow down the prime number
>>fetching operation, but it would be interesting to know by how much,
>>so that we can know the price we pay for adding progress bars to our
>>applications.
>>
>>Any ideas why my progress bar isn't working?
>
>The import() function doesn't have any meaning before or after the
>ChunkFilter command, only during it, and then it's returning text,
>not a number. You probably want that line to read
>
>progressbar "Background", "Slider", P, nmax
>
>Dave
Thanks, Dave. Progress bar works fine and only slows things down by a
few seconds in any reasonable sized field of numbers.
For all you Panorama prime programmers:
Speaking of reasonable sized fields, I mistakenly typed in 10 million
(instead of one million) for the numbers field. I had to use
extendedexpressionstack to get the procedure to even create the
initial number field. Two hours and 32 minutes later, the procedure
returned 664, 579 primes.
Here's what the procedure looks like with the progress bar code and
extendedexpression stack added:
Local P,PNumbers,nmax
permanent n,prime,tstop
tstop = info("TickCount")
if datatype("n")="Text"
n=val(n)
endif
nmax=sqr(n)\1
if n > 500000
extendedexpressionstack
endif
PNumbers=rep("x",(n-3)\2)
characterfilter PNumbers, PNumbers, longword(2*seq()+3)
P=3
prime="2, "
Loop
prime=prime+str(P)+", "
chunkfilter 4, PNumbers, PNumbers, ?( (binaryvalue(import()) mod
P) = 0,"",import())
progressbar "Background", "Slider", P, nmax
P=binaryvalue(PNumbers[1;4])
PNumbers=PNumbers[5,-1]
Until P>nmax
chunkfilter 4, PNumbers, PNumbers, str(binaryvalue(import())) + ", "
prime=prime+str(P)+", "+PNumbers[1,-3]
tstop = info("TickCount")-tstop
if n > 500000
normalexpressionstack
endif
ShowVariables n,prime,tstop
--
Jay Schille
More information about the Qna
mailing list