Click the green flag to generate prime numbers. Click the red circle to stop. You probably could have guessed that, couldn't you? What I changed: First you have to understand that with any two factors of a number, one is below the square root and one is above (unless they are the same number). Take 16, for example: Its square root is 4, so you could express 16 as 4 x 4. If you were to take one of the numbers and lower it, then the other must be increased, so if you decided to halve one of the 4s you would need to double the other one: 16 = (4/2) x (4*2) = 2 * 8 Do you see with that any two factors of a number, one must be above the square root and one must be below? Next: Useless division - If a number divides by 4, then it must divide by 2. If a number divides by 6, then it must divide by 3 and 2. Why, then does one need to go through every single number and see if it divides by it if one could just test to see if it divides by the prime numbers? If I put these two facts together, the algorithm looks like this: When green flag clicked delete all of Prime Numbers add 2 to Prime Numbers add 3 to Prime Numbers set j to 3 forever change j by 2 set k to 1 repeat until ( (item k of Prime Numbers)^2 > j+1 ) or ( j mod (item k of Prime Numbers) = 0 ) change k by 1 if ( (item k of Prime Numbers)^2 >j+1) add j to Prime Numbers The script is slightly different inside as I am now using the "make a block" and using the "run without screen refresh" so it runs fast without turbo mode.
27/11/15: Now you don't have to click the upload button - it uploads any new primes you have generated when you click the stop button (thanks to TheLogFather for his project showing how you can make scripts execute when the stop button is clicked) 26/11/15: Cloud data added so when you start the project it syncs to the cloud and when you click the upload button it updates the cloud variable to add more primes to it (couldn't have done this without scratch.mit.edu/projects/87456898/ by Laddie12 as scratch variables are normally limited to 10240 digits which isn't enough to store the list in) Comment if you want me to make a cloud storage one (so anyone who runs the project contributes to the list of prime numbers).