diff options
| author | Federico Igne <git@federicoigne.com> | 2020-12-26 17:48:38 +0000 |
|---|---|---|
| committer | Federico Igne <git@federicoigne.com> | 2021-11-03 18:55:08 +0000 |
| commit | 02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch) | |
| tree | 8e39798fcaf27931d91c2088423fd4e97adcfc2d /nth-prime | |
| parent | 4e2052c4d792540c2f742b2c2a081b11117ed41d (diff) | |
| download | exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip | |
Move Rust exercises in a subdirectory
Diffstat (limited to 'nth-prime')
| -rw-r--r-- | nth-prime/.exercism/metadata.json | 1 | ||||
| -rw-r--r-- | nth-prime/.gitignore | 8 | ||||
| -rw-r--r-- | nth-prime/Cargo.toml | 6 | ||||
| -rw-r--r-- | nth-prime/README.md | 92 | ||||
| -rw-r--r-- | nth-prime/src/lib.rs | 8 | ||||
| -rw-r--r-- | nth-prime/tests/nth-prime.rs | 21 |
6 files changed, 0 insertions, 136 deletions
diff --git a/nth-prime/.exercism/metadata.json b/nth-prime/.exercism/metadata.json deleted file mode 100644 index 5c5337e..0000000 --- a/nth-prime/.exercism/metadata.json +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | {"track":"rust","exercise":"nth-prime","id":"7ed3faca556f4c23a55b30fae8b69047","url":"https://exercism.io/my/solutions/7ed3faca556f4c23a55b30fae8b69047","handle":"dyamon","is_requester":true,"auto_approve":false} \ No newline at end of file | ||
diff --git a/nth-prime/.gitignore b/nth-prime/.gitignore deleted file mode 100644 index db7f315..0000000 --- a/nth-prime/.gitignore +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # Generated by Cargo | ||
| 2 | # will have compiled files and executables | ||
| 3 | /target/ | ||
| 4 | **/*.rs.bk | ||
| 5 | |||
| 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
| 7 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
| 8 | Cargo.lock | ||
diff --git a/nth-prime/Cargo.toml b/nth-prime/Cargo.toml deleted file mode 100644 index fc1c776..0000000 --- a/nth-prime/Cargo.toml +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2018" | ||
| 3 | name = "nth_prime" | ||
| 4 | version = "2.1.0" | ||
| 5 | |||
| 6 | [dependencies] | ||
diff --git a/nth-prime/README.md b/nth-prime/README.md deleted file mode 100644 index 425abde..0000000 --- a/nth-prime/README.md +++ /dev/null | |||
| @@ -1,92 +0,0 @@ | |||
| 1 | # Nth Prime | ||
| 2 | |||
| 3 | Given a number n, determine what the nth prime is. | ||
| 4 | |||
| 5 | By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that | ||
| 6 | the 6th prime is 13. | ||
| 7 | |||
| 8 | If your language provides methods in the standard library to deal with prime | ||
| 9 | numbers, pretend they don't exist and implement them yourself. | ||
| 10 | |||
| 11 | Remember that while people commonly count with 1-based indexing (i.e. "the 6th prime is 13"), many programming languages, including Rust, use 0-based indexing (i.e. `primes[5] == 13`). Use 0-based indexing for your implementation. | ||
| 12 | |||
| 13 | |||
| 14 | ## Rust Installation | ||
| 15 | |||
| 16 | Refer to the [exercism help page][help-page] for Rust installation and learning | ||
| 17 | resources. | ||
| 18 | |||
| 19 | ## Writing the Code | ||
| 20 | |||
| 21 | Execute the tests with: | ||
| 22 | |||
| 23 | ```bash | ||
| 24 | $ cargo test | ||
| 25 | ``` | ||
| 26 | |||
| 27 | All but the first test have been ignored. After you get the first test to | ||
| 28 | pass, open the tests source file which is located in the `tests` directory | ||
| 29 | and remove the `#[ignore]` flag from the next test and get the tests to pass | ||
| 30 | again. Each separate test is a function with `#[test]` flag above it. | ||
| 31 | Continue, until you pass every test. | ||
| 32 | |||
| 33 | If you wish to run all ignored tests without editing the tests source file, use: | ||
| 34 | |||
| 35 | ```bash | ||
| 36 | $ cargo test -- --ignored | ||
| 37 | ``` | ||
| 38 | |||
| 39 | To run a specific test, for example `some_test`, you can use: | ||
| 40 | |||
| 41 | ```bash | ||
| 42 | $ cargo test some_test | ||
| 43 | ``` | ||
| 44 | |||
| 45 | If the specific test is ignored use: | ||
| 46 | |||
| 47 | ```bash | ||
| 48 | $ cargo test some_test -- --ignored | ||
| 49 | ``` | ||
| 50 | |||
| 51 | To learn more about Rust tests refer to the [online test documentation][rust-tests] | ||
| 52 | |||
| 53 | Make sure to read the [Modules][modules] chapter if you | ||
| 54 | haven't already, it will help you with organizing your files. | ||
| 55 | |||
| 56 | ## Further improvements | ||
| 57 | |||
| 58 | After 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. | ||
| 59 | |||
| 60 | To format your solution, inside the solution directory use | ||
| 61 | |||
| 62 | ```bash | ||
| 63 | cargo fmt | ||
| 64 | ``` | ||
| 65 | |||
| 66 | To see, if your solution contains some common ineffective use cases, inside the solution directory use | ||
| 67 | |||
| 68 | ```bash | ||
| 69 | cargo clippy --all-targets | ||
| 70 | ``` | ||
| 71 | |||
| 72 | ## Submitting the solution | ||
| 73 | |||
| 74 | Generally 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. | ||
| 75 | |||
| 76 | ## Feedback, Issues, Pull Requests | ||
| 77 | |||
| 78 | The [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! | ||
| 79 | |||
| 80 | If 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). | ||
| 81 | |||
| 82 | [help-page]: https://exercism.io/tracks/rust/learning | ||
| 83 | [modules]: https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html | ||
| 84 | [cargo]: https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html | ||
| 85 | [rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html | ||
| 86 | |||
| 87 | ## Source | ||
| 88 | |||
| 89 | A variation on Problem 7 at Project Euler [http://projecteuler.net/problem=7](http://projecteuler.net/problem=7) | ||
| 90 | |||
| 91 | ## Submitting Incomplete Solutions | ||
| 92 | It's possible to submit an incomplete solution so you can see how others have completed the exercise. | ||
diff --git a/nth-prime/src/lib.rs b/nth-prime/src/lib.rs deleted file mode 100644 index ef9d7ea..0000000 --- a/nth-prime/src/lib.rs +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | fn is_prime(n: u32) -> bool { | ||
| 2 | let limit = (n as f64).sqrt() as u32; | ||
| 3 | (2..=limit).all(|x| n % x != 0) | ||
| 4 | } | ||
| 5 | |||
| 6 | pub fn nth(n: u32) -> u32 { | ||
| 7 | (2..).filter(|x| is_prime(*x)).nth(n as usize).unwrap() | ||
| 8 | } | ||
diff --git a/nth-prime/tests/nth-prime.rs b/nth-prime/tests/nth-prime.rs deleted file mode 100644 index b313ff2..0000000 --- a/nth-prime/tests/nth-prime.rs +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | use nth_prime as np; | ||
| 2 | |||
| 3 | #[test] | ||
| 4 | fn test_first_prime() { | ||
| 5 | assert_eq!(np::nth(0), 2); | ||
| 6 | } | ||
| 7 | |||
| 8 | #[test] | ||
| 9 | fn test_second_prime() { | ||
| 10 | assert_eq!(np::nth(1), 3); | ||
| 11 | } | ||
| 12 | |||
| 13 | #[test] | ||
| 14 | fn test_sixth_prime() { | ||
| 15 | assert_eq!(np::nth(5), 13); | ||
| 16 | } | ||
| 17 | |||
| 18 | #[test] | ||
| 19 | fn test_big_prime() { | ||
| 20 | assert_eq!(np::nth(10_000), 104_743); | ||
| 21 | } | ||
