ScratchData LogoScratchData
Back to fbrd's profile

Seive of Eratosthenes

FBfbrd•Created November 1, 2008
Seive of Eratosthenes
2
0
338 views
View on Scratch

Description

press up/down keys to change maxnum then press spacebar to tell it to start calculating. this finds every prime number up to maxnum huge maxnums take longer than tiny ones. Project: Seive of Eratosthenes Author: fbrd Scratch: 1.3 (release of 2-Sep-08) History: 2008-11-1 09:44:04 save Seive of Eratosthenes 2008-11-1 10:35:26 save Seive of Eratosthenes 2008-11-1 10:52:05 share Seive of Eratosthenes (Super Prime Finder) fbrd Totals: Sprites: 1 Stacks: 5 Unique costumes: 2 Unique sounds: 1 -------- Sprite: Stage Costumes (1): background1 (480x360) Sounds (1): pop (0:00:00) Stacks (3): when I receive "start" reset timer forever set "time used" to timer end when I receive "Done!" stop all end when green flag clicked delete all of "primes" set "index" to 1 set "change speed" to 0 set "maxnum" to 200 repeat until key "space" pressed? if key "down arrow" pressed? repeat until not key "down arrow" pressed? change "change speed" by -0.1 change "maxnum" by change speed set "change speed" to change speed * 0.98 set "change speed" to 0 set "maxnum" to round maxnum if key "up arrow" pressed? repeat until not key "up arrow" pressed? change "change speed" by 0.1 change "maxnum" by change speed set "change speed" to change speed * 0.98 set "change speed" to 0 set "maxnum" to round maxnum if maxnum < 2 set "maxnum" to 2 broadcast "start" repeat until index = maxnum change "index" by 1 add index to "primes" set "index" to 0 set "cprime" to 1 repeat until cprime = round "sqrt" of length of "primes" set "index" to cprime repeat until index = length of "primes" change "index" by 1 if 0 = item index of "primes" mod item cprime of "primes" delete index of "primes" change "index" by -1 change "cprime" by 1 broadcast "Done!" end -------- Sprite: Sprite1 Costumes (1): costume1 (480x360) Sounds (0): Stacks (2): when I receive "Done!" hide end when green flag clicked show end --------

Project Details

Project ID308491
CreatedNovember 1, 2008
Last ModifiedNovember 1, 2008
SharedNovember 1, 2008
Visibilityvisible
CommentsAllowed

Remix Information

Parent ProjectView Parent
Root ProjectView Root