diff --git a/config.json b/config.json index a4bb6dca9..69d5e9d30 100644 --- a/config.json +++ b/config.json @@ -154,6 +154,17 @@ "mathematics" ] }, + { + "uuid": "9de405e1-3a05-43cb-8eb3-00b81a2968e9", + "slug": "series", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "vectors", + "strings" + ] + }, { "uuid": "f9afd650-8103-4373-a284-fa4ecfee7207", "slug": "collatz-conjecture", diff --git a/exercises/series/.gitignore b/exercises/series/.gitignore new file mode 100644 index 000000000..d236530ab --- /dev/null +++ b/exercises/series/.gitignore @@ -0,0 +1,3 @@ +# Ignore Cargo.lock if creating a library +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock diff --git a/exercises/series/Cargo.toml b/exercises/series/Cargo.toml new file mode 100644 index 000000000..f8da3cd2d --- /dev/null +++ b/exercises/series/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "series" +version = "0.1.0" + +[dependencies] diff --git a/exercises/series/README.md b/exercises/series/README.md new file mode 100644 index 000000000..0d8b89a0e --- /dev/null +++ b/exercises/series/README.md @@ -0,0 +1,60 @@ +# Series + +Given a string of digits, output all the contiguous substrings of length `n` in +that string. + +For example, the string "49142" has the following 3-digit series: + +- 491 +- 914 +- 142 + +And the following 4-digit series: + +- 4914 +- 9142 + +And if you ask for a 6-digit series from a 5-digit string, you deserve +whatever you get. + +Note that these series are only required to occupy *adjacent positions* +in the input; the digits need not be *numerically consecutive*. + +## Rust Installation + +Refer to the [exercism help page][help-page] for Rust installation and learning +resources. + +## Writing the Code + +Execute the tests with: + +```bash +$ cargo test +``` + +All but the first test have been ignored. After you get the first test to +pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests +to pass again. The test file is located in the `tests` directory. You can +also remove the ignore flag from all the tests to get them to run all at once +if you wish. + +Make sure to read the [Modules](https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html) chapter if you +haven't already, it will help you with organizing your files. + +## Feedback, Issues, Pull Requests + +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](https://github.com/orgs/exercism/teams/rust) are happy to help! + +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). + +[help-page]: http://exercism.io/languages/rust +[modules]: https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html +[cargo]: https://doc.rust-lang.org/book/second-edition/ch14-00-more-about-cargo.html + +## Source + +A subset of the Problem 8 at Project Euler [http://projecteuler.net/problem=8](http://projecteuler.net/problem=8) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/series/example.rs b/exercises/series/example.rs new file mode 100644 index 000000000..ed179b49b --- /dev/null +++ b/exercises/series/example.rs @@ -0,0 +1,13 @@ +pub fn series(digits: &str, len: usize) -> Vec { + match len { + 0 => vec!["".to_string(); digits.len() + 1], + _ => { + digits + .chars() + .collect::>() + .windows(len) + .map(|window| window.into_iter().collect::()) + .collect::>() + } + } +} diff --git a/exercises/series/src/lib.rs b/exercises/series/src/lib.rs new file mode 100644 index 000000000..58427946d --- /dev/null +++ b/exercises/series/src/lib.rs @@ -0,0 +1,3 @@ +pub fn series(_digits: &str, _len: usize) -> Vec { + unimplemented!() +} diff --git a/exercises/series/tests/series.rs b/exercises/series/tests/series.rs new file mode 100644 index 000000000..ce53c3666 --- /dev/null +++ b/exercises/series/tests/series.rs @@ -0,0 +1,34 @@ +extern crate series; +use series::*; + +#[test] +fn test_with_zero_length() { + let expected = vec!["".to_string(); 6]; + assert_eq!(series("92017", 0), expected); +} + +#[test] +#[ignore] +fn test_with_length_2() { + let expected = vec![ + "92".to_string(), + "20".to_string(), + "01".to_string(), + "17".to_string(), + ]; + assert_eq!(series("92017", 2), expected); +} + +#[test] +#[ignore] +fn test_with_numbers_length() { + let expected = vec!["92017".to_string()]; + assert_eq!(series("92017", 5), expected); +} + +#[test] +#[ignore] +fn test_too_long() { + let expected: Vec = vec![]; + assert_eq!(series("92017", 6), expected); +}