Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions exercises/series/.gitignore
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions exercises/series/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "series"
version = "0.1.0"

[dependencies]
60 changes: 60 additions & 0 deletions exercises/series/README.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions exercises/series/example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub fn series(digits: &str, len: usize) -> Vec<String> {
match len {
0 => vec!["".to_string(); digits.len() + 1],
_ => {
digits
.chars()
.collect::<Vec<char>>()
.windows(len)
.map(|window| window.into_iter().collect::<String>())
.collect::<Vec<String>>()
}
}
}
3 changes: 3 additions & 0 deletions exercises/series/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn series(_digits: &str, _len: usize) -> Vec<String> {
unimplemented!()
}
34 changes: 34 additions & 0 deletions exercises/series/tests/series.rs
Original file line number Diff line number Diff line change
@@ -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<String> = vec![];
assert_eq!(series("92017", 6), expected);
}