2 ms·
EDIT: I think I follow how this works now. I didn't understand the sieve itself, so the co-routines was throwing me for a loop. We get all the numbers from 2 t
by Night_Thastus 4y ago
EDIT: I think I follow how this works now. I didn't understand the sieve itself, so the co-routines was throwing me for a loop.
We get all the numbers from 2 to 40, print out 2, then eliminate all the entries divisible by 2. Now we're left with 3, 5, 7, 9, etc.
We print out 3, then remove all the entries divisible by 3.
This repeats until we've hit the end (40). The next number after a round of eliminations will always be a prime.
- layer8 4y agoYeah, the sieve use-case is a bit too clever IMO to be a good introductory example.