Skip to content

Commit 1418a60

Browse files
committed
Add Eratosthene's sieve project
1 parent e535d65 commit 1418a60

6 files changed

Lines changed: 7189 additions & 0 deletions

File tree

sieve/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# metadata
2+
.exercism
3+
4+
# Dependency directories
5+
node_modules

sieve/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Sieve
2+
3+
Use the Sieve of Eratosthenes to find all the primes from 2 up to a given
4+
number.
5+
6+
The Sieve of Eratosthenes is a simple, ancient algorithm for finding all
7+
prime numbers up to any given limit. It does so by iteratively marking as
8+
composite (i.e. not prime) the multiples of each prime, starting with the
9+
multiples of 2. It does not use any division or remainder operation.
10+
11+
Create your range, starting at two and continuing up to and including the given limit. (i.e. [2, limit])
12+
13+
The algorithm consists of repeating the following over and over:
14+
15+
- take the next available unmarked number in your list (it is prime)
16+
- mark all the multiples of that number (they are not prime)
17+
18+
Repeat until you have processed each number in your range.
19+
20+
When the algorithm terminates, all the numbers in the list that have not
21+
been marked are prime.
22+
23+
The wikipedia article has a useful graphic that explains the algorithm:
24+
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
25+
26+
Notice that this is a very specific algorithm, and the tests don't check
27+
that you've implemented the algorithm, only that you've come up with the
28+
correct list of primes. A good first test is to check that you do not use
29+
division or remainder operations (div, /, mod or % depending on the
30+
language).
31+
32+
## Setup
33+
34+
Go through the setup instructions for Javascript to
35+
install the necessary dependencies:
36+
37+
[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation)
38+
39+
## Requirements
40+
41+
Install assignment dependencies:
42+
43+
```bash
44+
$ npm install
45+
```
46+
47+
## Making the test suite pass
48+
49+
Execute the tests with:
50+
51+
```bash
52+
$ npm test
53+
```
54+
55+
In the test suites all tests but the first have been skipped.
56+
57+
Once you get a test passing, you can enable the next one by
58+
changing `xtest` to `test`.
59+
60+
61+
## Source
62+
63+
Sieve of Eratosthenes at Wikipedia [http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
64+
65+
## Submitting Incomplete Solutions
66+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

0 commit comments

Comments
 (0)