sieve-of-eras_3


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT?


-------
Sieve of Era..whoever.
Only turtles with prime labels remain
consecutive primes are yellow

NET LOGO FEATURES


-------------
This sieve is designed to work even though the turtles are created and eliminated in random order!

Procedures

NetLogo Version: NetLogo 4.0.4

to startup
   doit
end

to doit
   ca
   no-display
   ask patches
   [ sprout 1
     [ set label (pxcor + pycor * (max-pxcor + 1) ) set size 0 ]
   ]
   ; ask turtles with [ label mod 6 = 0 ] [ set pcolor blue ]
   ask turtles with [ label mod 2 = 0 ] [ die ]

   display
   let stop-number sqrt ( (max-pxcor + 1 )* (max-pycor + 1))
   let n 3
   while [n < stop-number  ]
   [
     if any? turtles with [ label = n ]
     [
       ask turtles with [ label > n and label mod n = 0 ] [ die ]
       ;; display
     ]
     set n n + 1
   ]
   display
   ask turtles
   [ ; set pcolor pink
     if any? turtles with [ label = [label] of myself - 2 or label = [label] of myself + 2 ]
     [ set label-color yellow 
       ; set pcolor red
     ]
    
   ]
   display
end

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download sieve-of-eras_3 --