Skip to content

silawrenc/prime-sieves

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prime sieve implementations in javascript

Sieve of Eratosthenes

A handful of common prime sieve implementations in javascript. Each sieve accepts two arguments. The first is simply the size of the sieve, the second is a toggle function which is called each time a value is "sieved" (or unsieved). This makes it easy to build animations decoupled from the sieving algorithm.

The toggle function has a signature of toggle(value, flag) where the flag corresponds to the state of the value in the sieve. I.e. if the flag is false, the value has been 'sieved' and is no longer active in the sieve, if it is true then the value has been re-included in the sieve (see e.g. Sieve of Atkin for when that might happen).

Usage

The easiest way to install is via NPM.

var sieves = require('prime-sieves');
// some kind of visual behaviour function
function sieve(value, flag) {
  $('#animation > span')[value].toggleClass('active', flag)
};
// kick things off
sieves.eratosthenes(100, sieve);

About

Various prime sieve implementations in js

Resources

License

Stars

Watchers

Forks

Packages

No packages published