Skip to content

Day 244 #503

Closed
Closed

Description

@vaskoz

Good morning! Here's your coding interview problem for today.

This problem was asked by Square.

The Sieve of Eratosthenes is an algorithm used to generate all prime numbers smaller than N. The method is to take increasingly larger prime numbers, and mark their multiples as composite.

For example, to find all primes less than 100, we would first mark [4, 6, 8, ...] (multiples of two), then [6, 9, 12, ...] (multiples of three), and so on. Once we have done this for all primes less than N, the unmarked numbers that remain will be prime.

Implement this algorithm.

Bonus: Create a generator that produces primes indefinitely (that is, without taking N as an input).

Activity

  1. self-assigned this
    on Apr 23, 2019
  2. vaskoz commented on Apr 23, 2019

    @vaskoz
    OwnerAuthor
  3. vaskoz commented on Apr 23, 2019

    @vaskoz
    OwnerAuthor

    Bonus question. Implemented as a read channel of ints.
    https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Incremental_sieve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions