Skip to content

gsurma/prime_numbers_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prime numbers generator

Eratosthenes Sieve based prime numbers generator written in Swift.

How does it work?

To find all the prime numbers less than or equal to a given integer n:

  1. 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.
  2. Create an empty array for storing primes.
  3. Mark first two bools as false, as both 0 and 1 are not primes.
  4. Then iterate through the sieve and for every true value
    • mark it's each multiple as not prime
    • add it to the primes array
  5. Both multiplication and iteration through the sieve are limited by upper bound n.
  6. Ultimately we have an array of primes.

Author

Greg (Grzegorz) Surma

PORTFOLIO

GITHUB

BLOG

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages