Eratosthenes Sieve based prime numbers generator written in Swift.
To find all the prime numbers less than or equal to a given integer n:
- Create an Eratosthenes Sieve. Initially, it should be an array of n true bools. Each bool indicates whether a value on a corresponding index is a prime or not.
- Create an empty array for storing primes.
- Mark first two bools as false, as both 0 and 1 are not primes.
- Then iterate through the sieve and for every true value
- mark it's each multiple as not prime
- add it to the primes array
- Both multiplication and iteration through the sieve are limited by upper bound n.
- Ultimately we have an array of primes.
Greg (Grzegorz) Surma