aboutsummaryrefslogtreecommitdiff
path: root/rust/sieve/README.md
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-12-29 09:27:22 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commitbfe7a2e6d7e51b3973a169e592c7f507a7d96c2c (patch)
treec38e5697443b310a7035a10c04b46b3796202962 /rust/sieve/README.md
parentf7620da880e3dade5fdce6fd0f51f290d4353654 (diff)
downloadexercism-bfe7a2e6d7e51b3973a169e592c7f507a7d96c2c.tar.gz
exercism-bfe7a2e6d7e51b3973a169e592c7f507a7d96c2c.zip
[rust] Sieve
Diffstat (limited to 'rust/sieve/README.md')
-rw-r--r--rust/sieve/README.md110
1 files changed, 110 insertions, 0 deletions
diff --git a/rust/sieve/README.md b/rust/sieve/README.md
new file mode 100644
index 0000000..8e01d40
--- /dev/null
+++ b/rust/sieve/README.md
@@ -0,0 +1,110 @@
1# Sieve
2
3Use the Sieve of Eratosthenes to find all the primes from 2 up to a given
4number.
5
6The Sieve of Eratosthenes is a simple, ancient algorithm for finding all
7prime numbers up to any given limit. It does so by iteratively marking as
8composite (i.e. not prime) the multiples of each prime, starting with the
9multiples of 2. It does not use any division or remainder operation.
10
11Create your range, starting at two and continuing up to and including the given limit. (i.e. [2, limit])
12
13The 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
18Repeat until you have processed each number in your range.
19
20When the algorithm terminates, all the numbers in the list that have not
21been marked are prime.
22
23The wikipedia article has a useful graphic that explains the algorithm:
24https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
25
26Notice that this is a very specific algorithm, and the tests don't check
27that you've implemented the algorithm, only that you've come up with the
28correct list of primes. A good first test is to check that you do not use
29division or remainder operations (div, /, mod or % depending on the
30language).
31
32## Rust Installation
33
34Refer to the [exercism help page][help-page] for Rust installation and learning
35resources.
36
37## Writing the Code
38
39Execute the tests with:
40
41```bash
42$ cargo test
43```
44
45All but the first test have been ignored. After you get the first test to
46pass, open the tests source file which is located in the `tests` directory
47and remove the `#[ignore]` flag from the next test and get the tests to pass
48again. Each separate test is a function with `#[test]` flag above it.
49Continue, until you pass every test.
50
51If you wish to run all ignored tests without editing the tests source file, use:
52
53```bash
54$ cargo test -- --ignored
55```
56
57To run a specific test, for example `some_test`, you can use:
58
59```bash
60$ cargo test some_test
61```
62
63If the specific test is ignored use:
64
65```bash
66$ cargo test some_test -- --ignored
67```
68
69To learn more about Rust tests refer to the [online test documentation][rust-tests]
70
71Make sure to read the [Modules][modules] chapter if you
72haven't already, it will help you with organizing your files.
73
74## Further improvements
75
76After you have solved the exercise, please consider using the additional utilities, described in the [installation guide](https://exercism.io/tracks/rust/installation), to further refine your final solution.
77
78To format your solution, inside the solution directory use
79
80```bash
81cargo fmt
82```
83
84To see, if your solution contains some common ineffective use cases, inside the solution directory use
85
86```bash
87cargo clippy --all-targets
88```
89
90## Submitting the solution
91
92Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
93
94## Feedback, Issues, Pull Requests
95
96The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!
97
98If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md).
99
100[help-page]: https://exercism.io/tracks/rust/learning
101[modules]: https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html
102[cargo]: https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html
103[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
104
105## Source
106
107Sieve of Eratosthenes at Wikipedia [http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
108
109## Submitting Incomplete Solutions
110It's possible to submit an incomplete solution so you can see how others have completed the exercise.