Python Forum
sieve of eratosthenes implementation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sieve of eratosthenes implementation
#6
Quote:It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the first prime number,

You are not doing that, instead your filter comparing each current number to all past numbers. Essentially it's backwards. Also, your first example starts with a list of primes which is not at all part of the original design.

While both generate primes by use of filtering, neither is actually an example of the sieve of eratosthenes.

It's good work, excellent in fact, just not the right work for the question. OP asked for an example that explained how the sieve of eratosthenes worked. Neither of your examples does that. Instead you presented optimized code which is difficult a novice such as OP to understand. If OP had asked how do I generate prime numbers efficiently then your answers would have been suitable.
Reply


Messages In This Thread
RE: sieve of eratosthenes implementation - by Clunk_Head - Dec-21-2019, 02:59 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020