This page runs javascript code to find prime numbers up to 2,000,000.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
README.md
index.html

README.md

Sieve-of-Eratosthenes

This page runs javascript code to find prime numbers up to 2,000,000 a very large number, might I say tens of millions!?! :bowtie:

This project optimizes the algorithm based on the Sieve of Eratosthenes, an ancient Greek mathematician, to find prime numbers. The code is optimized using memoization techniques. There are two techiniques being used:

  1. I being by defining a memoize function on the prototype of the built-in Function, see here for details, for caching prior results. Within the running application, I can almost instantaneously provide results for values previously entered. 🕐

  2. I initialize an array of primes and an array for the sieve outside the main function call, and I have several helper functions for determining the starting point for the sieve algorithm. This means that while searching for 10,000 primes may take x amount of time, searching for 20,000 afterwards may take an equal amount of time, perhaps even less. This enables someone to incrementally get the algorithm to return tens of millions of primes without crashing the browser. In my first attempt, just to have fun replicating the algorithm, my app topped at 2 Million, and took almost a minute. 💎

This project is best viewed on modern browsers, though some of the code could be brougth more up-to-date, so to speak.

https://wesleylhandy.github.io/Sieve-of-Eratosthenes/