## Need help creating a sieve of Eratosthenes in Scratch

Arithmetic, algebra, number theory, sequence and series, analysis, ...
jkibbe
Posts: 1
Joined: Tue Nov 19, 2013 4:34 pm

### Need help creating a sieve of Eratosthenes in Scratch

Here's what I have so far:

http://scratch.mit.edu/projects/14460081/

I have been trying to make it work for a while now, but it seems to get hung up on perfect squares and maybe multiples of 5. I think it is because I am trying to use multiple if/else blocks instead of a while block (Scratch doesn't have these). I've always been able to find a workaround, but now I'm just confused. Any advice is greatly appreciated!

RagingCain
Posts: 3
Joined: Wed Apr 29, 2015 3:31 pm

### Re: Need help creating a sieve of Eratosthenes in Scratch

This was a working solution in C#, not Scratch, but may help wanderers.

Code: Select all

    private static List<long> SieveOfEratosthenes()
{
List<long> PrimesFound = new List<long>();

long SquareRoot = (long)Math.Sqrt(MAX_VALUE);
BitArray Eliminated = new BitArray(MAX_VALUE + 1);

for (long i = 3; i <= MAX_VALUE; i += 2)
{
if (Eliminated[i] != true)
{
}