init commit
This commit is contained in:
commit
d2ff52dc39
792 changed files with 35546 additions and 0 deletions
35
accumulate/.exercism/config.json
Normal file
35
accumulate/.exercism/config.json
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"blurb": "Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.",
|
||||||
|
"authors": [
|
||||||
|
"sacherjj"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"attilahorvath",
|
||||||
|
"ccouzens",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"Emerentius",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"lutostag",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/accumulate.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Conversation with James Edward Gray II",
|
||||||
|
"source_url": "https://twitter.com/jeg2"
|
||||||
|
}
|
1
accumulate/.exercism/metadata.json
Normal file
1
accumulate/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"accumulate","id":"17050a3afba8463e8c87aab51298e639","url":"https://exercism.org/tracks/rust/exercises/accumulate","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
accumulate/.gitignore
vendored
Normal file
8
accumulate/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
6
accumulate/Cargo.toml
Normal file
6
accumulate/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "accumulate"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
[dependencies]
|
85
accumulate/HELP.md
Normal file
85
accumulate/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
71
accumulate/README.md
Normal file
71
accumulate/README.md
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
# Accumulate
|
||||||
|
|
||||||
|
Welcome to Accumulate on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Implement the `accumulate` operation, which, given a collection and an
|
||||||
|
operation to perform on each element of the collection, returns a new
|
||||||
|
collection containing the result of applying that operation to each element of
|
||||||
|
the input collection.
|
||||||
|
|
||||||
|
Given the collection of numbers:
|
||||||
|
|
||||||
|
- 1, 2, 3, 4, 5
|
||||||
|
|
||||||
|
And the operation:
|
||||||
|
|
||||||
|
- square a number (`x => x * x`)
|
||||||
|
|
||||||
|
Your code should be able to produce the collection of squares:
|
||||||
|
|
||||||
|
- 1, 4, 9, 16, 25
|
||||||
|
|
||||||
|
Check out the test suite to see the expected function signature.
|
||||||
|
|
||||||
|
## Restrictions
|
||||||
|
|
||||||
|
Keep your hands off that collect/map/fmap/whatchamacallit functionality
|
||||||
|
provided by your standard library!
|
||||||
|
Solve this one yourself using other basic tools instead.
|
||||||
|
|
||||||
|
It may help to look at the Fn\* traits:
|
||||||
|
[Fn](https://doc.rust-lang.org/std/ops/trait.Fn.html),
|
||||||
|
[FnMut](https://doc.rust-lang.org/std/ops/trait.FnMut.html) and
|
||||||
|
[FnOnce](https://doc.rust-lang.org/std/ops/trait.FnOnce.html).
|
||||||
|
|
||||||
|
Help with passing a closure into a function may be found in
|
||||||
|
the ["closures as input parameters" section](https://doc.rust-lang.org/stable/rust-by-example/fn/closures/input_parameters.html) of
|
||||||
|
[Rust by Example](https://doc.rust-lang.org/stable/rust-by-example/).
|
||||||
|
|
||||||
|
The tests for this exercise will cause compile time errors,
|
||||||
|
if your function signature does not fit them, even when they're not run.
|
||||||
|
You may want to comment some tests out and generalize your solution piece by piece.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @sacherjj
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @attilahorvath
|
||||||
|
- @ccouzens
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @Emerentius
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @lutostag
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Conversation with James Edward Gray II - https://twitter.com/jeg2
|
4
accumulate/src/lib.rs
Normal file
4
accumulate/src/lib.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/// What should the type of _function be?
|
||||||
|
pub fn map(input: Vec<i32>, _function: ???) -> Vec<i32> {
|
||||||
|
unimplemented!("Transform input vector {:?} using passed function", input);
|
||||||
|
}
|
75
accumulate/tests/accumulate.rs
Normal file
75
accumulate/tests/accumulate.rs
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
use accumulate::map;
|
||||||
|
|
||||||
|
fn square(x: i32) -> i32 {
|
||||||
|
x * x
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn func_single() {
|
||||||
|
let input = vec![2];
|
||||||
|
let expected = vec![4];
|
||||||
|
assert_eq!(map(input, square), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn func_multi() {
|
||||||
|
let input = vec![2, 3, 4, 5];
|
||||||
|
let expected = vec![4, 9, 16, 25];
|
||||||
|
assert_eq!(map(input, square), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn closure() {
|
||||||
|
let input = vec![2, 3, 4, 5];
|
||||||
|
let expected = vec![4, 9, 16, 25];
|
||||||
|
assert_eq!(map(input, |x| x * x), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn closure_floats() {
|
||||||
|
let input = vec![2.0, 3.0, 4.0, 5.0];
|
||||||
|
let expected = vec![4.0, 9.0, 16.0, 25.0];
|
||||||
|
assert_eq!(map(input, |x| x * x), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn strings() {
|
||||||
|
let input = vec!["1".to_string(), "2".into(), "3".into()];
|
||||||
|
let expected = vec!["11".to_string(), "22".into(), "33".into()];
|
||||||
|
assert_eq!(map(input, |s| s.repeat(2)), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn change_in_type() {
|
||||||
|
let input: Vec<&str> = vec!["1", "2", "3"];
|
||||||
|
let expected: Vec<String> = vec!["1".into(), "2".into(), "3".into()];
|
||||||
|
assert_eq!(map(input, |s| s.to_string()), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn mutating_closure() {
|
||||||
|
let mut counter = 0;
|
||||||
|
let input = vec![-2, 3, 4, -5];
|
||||||
|
let expected = vec![2, 3, 4, 5];
|
||||||
|
let result = map(input, |x: i64| {
|
||||||
|
counter += 1;
|
||||||
|
x.abs()
|
||||||
|
});
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
assert_eq!(counter, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn minimal_bounds_on_input_and_output() {
|
||||||
|
// must be able to accept arbitrary input and output types
|
||||||
|
struct Foo;
|
||||||
|
struct Bar;
|
||||||
|
map(vec![Foo], |_| Bar);
|
||||||
|
}
|
39
acronym/.exercism/config.json
Normal file
39
acronym/.exercism/config.json
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"blurb": "Convert a long phrase to its acronym",
|
||||||
|
"authors": [
|
||||||
|
"gregcline"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"AndrewKvalheim",
|
||||||
|
"ClashTheBunny",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"IanWhitney",
|
||||||
|
"ktomsic",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"navossoc",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"thvdburgt",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/acronym.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Julien Vanier",
|
||||||
|
"source_url": "https://github.com/monkbroc"
|
||||||
|
}
|
1
acronym/.exercism/metadata.json
Normal file
1
acronym/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"acronym","id":"4fb0476f71364e048e5e336d5bf66280","url":"https://exercism.org/tracks/rust/exercises/acronym","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
acronym/.gitignore
vendored
Normal file
8
acronym/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
6
acronym/Cargo.toml
Normal file
6
acronym/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "acronym"
|
||||||
|
version = "1.7.0"
|
||||||
|
|
||||||
|
[dependencies]
|
85
acronym/HELP.md
Normal file
85
acronym/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
44
acronym/README.md
Normal file
44
acronym/README.md
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# Acronym
|
||||||
|
|
||||||
|
Welcome to Acronym on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Convert a phrase to its acronym.
|
||||||
|
|
||||||
|
Techies love their TLA (Three Letter Acronyms)!
|
||||||
|
|
||||||
|
Help generate some jargon by writing a program that converts a long name
|
||||||
|
like Portable Network Graphics to its acronym (PNG).
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @gregcline
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @AndrewKvalheim
|
||||||
|
- @ClashTheBunny
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @IanWhitney
|
||||||
|
- @ktomsic
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @navossoc
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @thvdburgt
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Julien Vanier - https://github.com/monkbroc
|
3
acronym/src/lib.rs
Normal file
3
acronym/src/lib.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn abbreviate(phrase: &str) -> String {
|
||||||
|
unimplemented!("Given the phrase '{}', return its acronym", phrase);
|
||||||
|
}
|
84
acronym/tests/acronym.rs
Normal file
84
acronym/tests/acronym.rs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#[test]
|
||||||
|
fn empty() {
|
||||||
|
assert_eq!(acronym::abbreviate(""), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn basic() {
|
||||||
|
assert_eq!(acronym::abbreviate("Portable Network Graphics"), "PNG");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn lowercase_words() {
|
||||||
|
assert_eq!(acronym::abbreviate("Ruby on Rails"), "ROR");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn camelcase() {
|
||||||
|
assert_eq!(acronym::abbreviate("HyperText Markup Language"), "HTML");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn punctuation() {
|
||||||
|
assert_eq!(acronym::abbreviate("First In, First Out"), "FIFO");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn all_caps_word() {
|
||||||
|
assert_eq!(
|
||||||
|
acronym::abbreviate("GNU Image Manipulation Program"),
|
||||||
|
"GIMP"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn all_caps_word_with_punctuation() {
|
||||||
|
assert_eq!(acronym::abbreviate("PHP: Hypertext Preprocessor"), "PHP");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn punctuation_without_whitespace() {
|
||||||
|
assert_eq!(
|
||||||
|
acronym::abbreviate("Complementary metal-oxide semiconductor"),
|
||||||
|
"CMOS"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn very_long_abbreviation() {
|
||||||
|
assert_eq!(
|
||||||
|
acronym::abbreviate(
|
||||||
|
"Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
|
||||||
|
),
|
||||||
|
"ROTFLSHTMDCOALM"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn consecutive_delimiters() {
|
||||||
|
assert_eq!(
|
||||||
|
acronym::abbreviate("Something - I made up from thin air"),
|
||||||
|
"SIMUFTA"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn apostrophes() {
|
||||||
|
assert_eq!(acronym::abbreviate("Halley's Comet"), "HC");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn underscore_emphasis() {
|
||||||
|
assert_eq!(acronym::abbreviate("The Road _Not_ Taken"), "TRNT");
|
||||||
|
}
|
27
affine-cipher/.exercism/config.json
Normal file
27
affine-cipher/.exercism/config.json
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"blurb": "Create an implementation of the Affine cipher, an ancient encryption algorithm from the Middle East.",
|
||||||
|
"authors": [
|
||||||
|
"ktomsic"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"ffflorian",
|
||||||
|
"petertseng"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/affine-cipher.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Wikipedia",
|
||||||
|
"source_url": "http://en.wikipedia.org/wiki/Affine_cipher"
|
||||||
|
}
|
1
affine-cipher/.exercism/metadata.json
Normal file
1
affine-cipher/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"affine-cipher","id":"5781682b18df4ae8a0244925a9f7d0db","url":"https://exercism.org/tracks/rust/exercises/affine-cipher","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
affine-cipher/.gitignore
vendored
Normal file
8
affine-cipher/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by exercism rust track exercise tool
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
affine-cipher/Cargo.toml
Normal file
4
affine-cipher/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "affine-cipher"
|
||||||
|
version = "2.0.0"
|
85
affine-cipher/HELP.md
Normal file
85
affine-cipher/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
94
affine-cipher/README.md
Normal file
94
affine-cipher/README.md
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
# Affine Cipher
|
||||||
|
|
||||||
|
Welcome to Affine Cipher on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Create an implementation of the affine cipher,
|
||||||
|
an ancient encryption system created in the Middle East.
|
||||||
|
|
||||||
|
The affine cipher is a type of monoalphabetic substitution cipher.
|
||||||
|
Each character is mapped to its numeric equivalent, encrypted with
|
||||||
|
a mathematical function and then converted to the letter relating to
|
||||||
|
its new numeric value. Although all monoalphabetic ciphers are weak,
|
||||||
|
the affine cypher is much stronger than the atbash cipher,
|
||||||
|
because it has many more keys.
|
||||||
|
|
||||||
|
The encryption function is:
|
||||||
|
|
||||||
|
`E(x) = (ax + b) mod m`
|
||||||
|
- where `x` is the letter's index from 0 - length of alphabet - 1
|
||||||
|
- `m` is the length of the alphabet. For the roman alphabet `m == 26`.
|
||||||
|
- and `a` and `b` make the key
|
||||||
|
|
||||||
|
The decryption function is:
|
||||||
|
|
||||||
|
`D(y) = a^-1(y - b) mod m`
|
||||||
|
- where `y` is the numeric value of an encrypted letter, ie. `y = E(x)`
|
||||||
|
- it is important to note that `a^-1` is the modular multiplicative inverse
|
||||||
|
of `a mod m`
|
||||||
|
- the modular multiplicative inverse of `a` only exists if `a` and `m` are
|
||||||
|
coprime.
|
||||||
|
|
||||||
|
To find the MMI of `a`:
|
||||||
|
|
||||||
|
`an mod m = 1`
|
||||||
|
- where `n` is the modular multiplicative inverse of `a mod m`
|
||||||
|
|
||||||
|
More information regarding how to find a Modular Multiplicative Inverse
|
||||||
|
and what it means can be found [here.](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse)
|
||||||
|
|
||||||
|
Because automatic decryption fails if `a` is not coprime to `m` your
|
||||||
|
program should return status 1 and `"Error: a and m must be coprime."`
|
||||||
|
if they are not. Otherwise it should encode or decode with the
|
||||||
|
provided key.
|
||||||
|
|
||||||
|
The Caesar (shift) cipher is a simple affine cipher where `a` is 1 and
|
||||||
|
`b` as the magnitude results in a static displacement of the letters.
|
||||||
|
This is much less secure than a full implementation of the affine cipher.
|
||||||
|
|
||||||
|
Ciphertext is written out in groups of fixed length, the traditional group
|
||||||
|
size being 5 letters, and punctuation is excluded. This is to make it
|
||||||
|
harder to guess things based on word boundaries.
|
||||||
|
|
||||||
|
## General Examples
|
||||||
|
|
||||||
|
- Encoding `test` gives `ybty` with the key a=5 b=7
|
||||||
|
- Decoding `ybty` gives `test` with the key a=5 b=7
|
||||||
|
- Decoding `ybty` gives `lqul` with the wrong key a=11 b=7
|
||||||
|
- Decoding `kqlfd jzvgy tpaet icdhm rtwly kqlon ubstx`
|
||||||
|
- gives `thequickbrownfoxjumpsoverthelazydog` with the key a=19 b=13
|
||||||
|
- Encoding `test` with the key a=18 b=13
|
||||||
|
- gives `Error: a and m must be coprime.`
|
||||||
|
- because a and m are not relatively prime
|
||||||
|
|
||||||
|
## Examples of finding a Modular Multiplicative Inverse (MMI)
|
||||||
|
|
||||||
|
- simple example:
|
||||||
|
- `9 mod 26 = 9`
|
||||||
|
- `9 * 3 mod 26 = 27 mod 26 = 1`
|
||||||
|
- `3` is the MMI of `9 mod 26`
|
||||||
|
- a more complicated example:
|
||||||
|
- `15 mod 26 = 15`
|
||||||
|
- `15 * 7 mod 26 = 105 mod 26 = 1`
|
||||||
|
- `7` is the MMI of `15 mod 26`
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @ktomsic
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @ffflorian
|
||||||
|
- @petertseng
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Wikipedia - http://en.wikipedia.org/wiki/Affine_cipher
|
18
affine-cipher/src/lib.rs
Normal file
18
affine-cipher/src/lib.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/// While the problem description indicates a return status of 1 should be returned on errors,
|
||||||
|
/// it is much more common to return a `Result`, so we provide an error type for the result here.
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
|
pub enum AffineCipherError {
|
||||||
|
NotCoprime(i32),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Encodes the plaintext using the affine cipher with key (`a`, `b`). Note that, rather than
|
||||||
|
/// returning a return code, the more common convention in Rust is to return a `Result`.
|
||||||
|
pub fn encode(plaintext: &str, a: i32, b: i32) -> Result<String, AffineCipherError> {
|
||||||
|
unimplemented!("Encode {} with the key ({}, {})", plaintext, a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decodes the ciphertext using the affine cipher with key (`a`, `b`). Note that, rather than
|
||||||
|
/// returning a return code, the more common convention in Rust is to return a `Result`.
|
||||||
|
pub fn decode(ciphertext: &str, a: i32, b: i32) -> Result<String, AffineCipherError> {
|
||||||
|
unimplemented!("Decode {} with the key ({}, {})", ciphertext, a, b);
|
||||||
|
}
|
146
affine-cipher/tests/affine-cipher.rs
Normal file
146
affine-cipher/tests/affine-cipher.rs
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
use affine_cipher::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn encode_yes() {
|
||||||
|
assert_eq!(encode("yes", 5, 7).unwrap(), "xbt")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_no() {
|
||||||
|
assert_eq!(encode("no", 15, 18).unwrap(), "fu")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_omg() {
|
||||||
|
assert_eq!(encode("OMG", 21, 3).unwrap(), "lvz")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_o_m_g() {
|
||||||
|
assert_eq!(encode("O M G", 25, 47).unwrap(), "hjp")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_mindblowingly() {
|
||||||
|
assert_eq!(encode("mindblowingly", 11, 15).unwrap(), "rzcwa gnxzc dgt")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_numbers() {
|
||||||
|
assert_eq!(
|
||||||
|
encode("Testing,1 2 3, testing.", 3, 4).unwrap(),
|
||||||
|
"jqgjc rw123 jqgjc rw"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_deep_thought() {
|
||||||
|
assert_eq!(
|
||||||
|
encode("Truth is fiction", 5, 17).unwrap(),
|
||||||
|
"iynia fdqfb ifje"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_all_the_letters() {
|
||||||
|
assert_eq!(
|
||||||
|
encode("The quick brown fox jumps over the lazy dog.", 17, 33).unwrap(),
|
||||||
|
"swxtj npvyk lruol iejdc blaxk swxmh qzglf"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn encode_with_a_not_coprime_to_m() {
|
||||||
|
const EXPECTED_ERROR: AffineCipherError = AffineCipherError::NotCoprime(6);
|
||||||
|
match encode("This is a test.", 6, 17) {
|
||||||
|
Err(EXPECTED_ERROR) => (),
|
||||||
|
Err(err) => panic!(
|
||||||
|
"Incorrect error: expected: {:?}, actual: {:?}.",
|
||||||
|
EXPECTED_ERROR, err
|
||||||
|
),
|
||||||
|
Ok(r) => panic!(
|
||||||
|
"Cannot encode/decode when a is coprime to m: expected: {:?}, actual: {:?}.",
|
||||||
|
EXPECTED_ERROR, r
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_exercism() {
|
||||||
|
assert_eq!(decode("tytgn fjr", 3, 7).unwrap(), "exercism")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_a_sentence() {
|
||||||
|
assert_eq!(
|
||||||
|
encode("anobstacleisoftenasteppingstone", 19, 16).unwrap(),
|
||||||
|
"qdwju nqcro muwhn odqun oppmd aunwd o"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
decode("qdwju nqcro muwhn odqun oppmd aunwd o", 19, 16).unwrap(),
|
||||||
|
"anobstacleisoftenasteppingstone"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_numbers() {
|
||||||
|
assert_eq!(
|
||||||
|
decode("odpoz ub123 odpoz ub", 25, 7).unwrap(),
|
||||||
|
"testing123testing"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_all_the_letters() {
|
||||||
|
assert_eq!(
|
||||||
|
decode("swxtj npvyk lruol iejdc blaxk swxmh qzglf", 17, 33).unwrap(),
|
||||||
|
"thequickbrownfoxjumpsoverthelazydog"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_with_no_spaces_in_input() {
|
||||||
|
assert_eq!(
|
||||||
|
decode("swxtjnpvyklruoliejdcblaxkswxmhqzglf", 17, 33).unwrap(),
|
||||||
|
"thequickbrownfoxjumpsoverthelazydog"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_with_too_many_spaces() {
|
||||||
|
assert_eq!(
|
||||||
|
decode("vszzm cly yd cg qdp", 15, 16).unwrap(),
|
||||||
|
"jollygreengiant"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decode_with_a_not_coprime_to_m() {
|
||||||
|
const EXPECTED_ERROR: AffineCipherError = AffineCipherError::NotCoprime(13);
|
||||||
|
match decode("Test", 13, 11) {
|
||||||
|
Err(EXPECTED_ERROR) => (),
|
||||||
|
Err(e) => panic!(
|
||||||
|
"Incorrect error: expected: {:?}, actual: {:?}.",
|
||||||
|
EXPECTED_ERROR, e
|
||||||
|
),
|
||||||
|
Ok(r) => panic!(
|
||||||
|
"Cannot encode/decode when a is coprime to m: expected: {:?}, actual: {:?}.",
|
||||||
|
EXPECTED_ERROR, r
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
35
all-your-base/.exercism/config.json
Normal file
35
all-your-base/.exercism/config.json
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"blurb": "Convert a number, represented as a sequence of digits in one base, to any other base.",
|
||||||
|
"authors": [
|
||||||
|
"jonasbb"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"CGMossa",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"IanWhitney",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"navossoc",
|
||||||
|
"nfiles",
|
||||||
|
"pedantic79",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/all-your-base.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
1
all-your-base/.exercism/metadata.json
Normal file
1
all-your-base/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"all-your-base","id":"295bb50dc5444550954c928ef4c19f5a","url":"https://exercism.org/tracks/rust/exercises/all-your-base","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
all-your-base/.gitignore
vendored
Normal file
8
all-your-base/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
all-your-base/Cargo.toml
Normal file
4
all-your-base/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "allyourbase"
|
||||||
|
version = "1.0.0"
|
85
all-your-base/HELP.md
Normal file
85
all-your-base/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
62
all-your-base/README.md
Normal file
62
all-your-base/README.md
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
# All Your Base
|
||||||
|
|
||||||
|
Welcome to All Your Base on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Convert a number, represented as a sequence of digits in one base, to any other base.
|
||||||
|
|
||||||
|
Implement general base conversion. Given a number in base **a**,
|
||||||
|
represented as a sequence of digits, convert it to base **b**.
|
||||||
|
|
||||||
|
## Note
|
||||||
|
|
||||||
|
- Try to implement the conversion yourself.
|
||||||
|
Do not use something else to perform the conversion for you.
|
||||||
|
|
||||||
|
## About [Positional Notation](https://en.wikipedia.org/wiki/Positional_notation)
|
||||||
|
|
||||||
|
In positional notation, a number in base **b** can be understood as a linear
|
||||||
|
combination of powers of **b**.
|
||||||
|
|
||||||
|
The number 42, *in base 10*, means:
|
||||||
|
|
||||||
|
(4 * 10^1) + (2 * 10^0)
|
||||||
|
|
||||||
|
The number 101010, *in base 2*, means:
|
||||||
|
|
||||||
|
(1 * 2^5) + (0 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (0 * 2^0)
|
||||||
|
|
||||||
|
The number 1120, *in base 3*, means:
|
||||||
|
|
||||||
|
(1 * 3^3) + (1 * 3^2) + (2 * 3^1) + (0 * 3^0)
|
||||||
|
|
||||||
|
I think you got the idea!
|
||||||
|
|
||||||
|
*Yes. Those three numbers above are exactly the same. Congratulations!*
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @jonasbb
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @CGMossa
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @IanWhitney
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @navossoc
|
||||||
|
- @nfiles
|
||||||
|
- @pedantic79
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
46
all-your-base/src/lib.rs
Normal file
46
all-your-base/src/lib.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum Error {
|
||||||
|
InvalidInputBase,
|
||||||
|
InvalidOutputBase,
|
||||||
|
InvalidDigit(u32),
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Convert a number between two bases.
|
||||||
|
///
|
||||||
|
/// A number is any slice of digits.
|
||||||
|
/// A digit is any unsigned integer (e.g. u8, u16, u32, u64, or usize).
|
||||||
|
/// Bases are specified as unsigned integers.
|
||||||
|
///
|
||||||
|
/// Return an `Err(.)` if the conversion is impossible.
|
||||||
|
/// The tests do not test for specific values inside the `Err(.)`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// You are allowed to change the function signature as long as all test still pass.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// Input
|
||||||
|
/// number: &[4, 2]
|
||||||
|
/// from_base: 10
|
||||||
|
/// to_base: 2
|
||||||
|
/// Result
|
||||||
|
/// Ok(vec![1, 0, 1, 0, 1, 0])
|
||||||
|
///
|
||||||
|
/// The example corresponds to converting the number 42 from decimal
|
||||||
|
/// which is equivalent to 101010 in binary.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Notes:
|
||||||
|
/// * The empty slice ( "[]" ) is equal to the number 0.
|
||||||
|
/// * Never output leading 0 digits, unless the input number is 0, in which the output must be `[0]`.
|
||||||
|
/// However, your function must be able to process input with leading 0 digits.
|
||||||
|
///
|
||||||
|
pub fn convert(number: &[u32], from_base: u32, to_base: u32) -> Result<Vec<u32>, Error> {
|
||||||
|
unimplemented!(
|
||||||
|
"Convert {:?} from base {} to base {}",
|
||||||
|
number,
|
||||||
|
from_base,
|
||||||
|
to_base
|
||||||
|
)
|
||||||
|
}
|
216
all-your-base/tests/all-your-base.rs
Normal file
216
all-your-base/tests/all-your-base.rs
Normal file
|
@ -0,0 +1,216 @@
|
||||||
|
use allyourbase as ayb;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn single_bit_one_to_decimal() {
|
||||||
|
let input_base = 2;
|
||||||
|
let input_digits = &[1];
|
||||||
|
let output_base = 10;
|
||||||
|
let output_digits = vec![1];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn binary_to_single_decimal() {
|
||||||
|
let input_base = 2;
|
||||||
|
let input_digits = &[1, 0, 1];
|
||||||
|
let output_base = 10;
|
||||||
|
let output_digits = vec![5];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn single_decimal_to_binary() {
|
||||||
|
let input_base = 10;
|
||||||
|
let input_digits = &[5];
|
||||||
|
let output_base = 2;
|
||||||
|
let output_digits = vec![1, 0, 1];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn binary_to_multiple_decimal() {
|
||||||
|
let input_base = 2;
|
||||||
|
let input_digits = &[1, 0, 1, 0, 1, 0];
|
||||||
|
let output_base = 10;
|
||||||
|
let output_digits = vec![4, 2];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn decimal_to_binary() {
|
||||||
|
let input_base = 10;
|
||||||
|
let input_digits = &[4, 2];
|
||||||
|
let output_base = 2;
|
||||||
|
let output_digits = vec![1, 0, 1, 0, 1, 0];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn trinary_to_hexadecimal() {
|
||||||
|
let input_base = 3;
|
||||||
|
let input_digits = &[1, 1, 2, 0];
|
||||||
|
let output_base = 16;
|
||||||
|
let output_digits = vec![2, 10];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn hexadecimal_to_trinary() {
|
||||||
|
let input_base = 16;
|
||||||
|
let input_digits = &[2, 10];
|
||||||
|
let output_base = 3;
|
||||||
|
let output_digits = vec![1, 1, 2, 0];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn fifteen_bit_integer() {
|
||||||
|
let input_base = 97;
|
||||||
|
let input_digits = &[3, 46, 60];
|
||||||
|
let output_base = 73;
|
||||||
|
let output_digits = vec![6, 10, 45];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn empty_list() {
|
||||||
|
let input_base = 2;
|
||||||
|
let input_digits = &[];
|
||||||
|
let output_base = 10;
|
||||||
|
let output_digits = vec![0];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn single_zero() {
|
||||||
|
let input_base = 10;
|
||||||
|
let input_digits = &[0];
|
||||||
|
let output_base = 2;
|
||||||
|
let output_digits = vec![0];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn multiple_zeros() {
|
||||||
|
let input_base = 10;
|
||||||
|
let input_digits = &[0, 0, 0];
|
||||||
|
let output_base = 2;
|
||||||
|
let output_digits = vec![0];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn leading_zeros() {
|
||||||
|
let input_base = 7;
|
||||||
|
let input_digits = &[0, 6, 0];
|
||||||
|
let output_base = 10;
|
||||||
|
let output_digits = vec![4, 2];
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Ok(output_digits)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn invalid_positive_digit() {
|
||||||
|
let input_base = 2;
|
||||||
|
let input_digits = &[1, 2, 1, 0, 1, 0];
|
||||||
|
let output_base = 10;
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Err(ayb::Error::InvalidDigit(2))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn input_base_is_one() {
|
||||||
|
let input_base = 1;
|
||||||
|
let input_digits = &[];
|
||||||
|
let output_base = 10;
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Err(ayb::Error::InvalidInputBase)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn output_base_is_one() {
|
||||||
|
let input_base = 2;
|
||||||
|
let input_digits = &[1, 0, 1, 0, 1, 0];
|
||||||
|
let output_base = 1;
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Err(ayb::Error::InvalidOutputBase)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn input_base_is_zero() {
|
||||||
|
let input_base = 0;
|
||||||
|
let input_digits = &[];
|
||||||
|
let output_base = 10;
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Err(ayb::Error::InvalidInputBase)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn output_base_is_zero() {
|
||||||
|
let input_base = 10;
|
||||||
|
let input_digits = &[7];
|
||||||
|
let output_base = 0;
|
||||||
|
assert_eq!(
|
||||||
|
ayb::convert(input_digits, input_base, output_base),
|
||||||
|
Err(ayb::Error::InvalidOutputBase)
|
||||||
|
);
|
||||||
|
}
|
39
allergies/.exercism/config.json
Normal file
39
allergies/.exercism/config.json
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"blurb": "Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.",
|
||||||
|
"authors": [
|
||||||
|
"EduardoBautista"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"ashleygwilliams",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"EduardoBautista",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"IanWhitney",
|
||||||
|
"kytrinyx",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"navossoc",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"taravancil",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/allergies.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Jumpstart Lab Warm-up",
|
||||||
|
"source_url": "http://jumpstartlab.com"
|
||||||
|
}
|
1
allergies/.exercism/metadata.json
Normal file
1
allergies/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"allergies","id":"e38d37faefc146d1821d01325e3aabfb","url":"https://exercism.org/tracks/rust/exercises/allergies","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
allergies/.gitignore
vendored
Normal file
8
allergies/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
allergies/Cargo.toml
Normal file
4
allergies/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "allergies"
|
||||||
|
version = "1.1.0"
|
85
allergies/HELP.md
Normal file
85
allergies/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
66
allergies/README.md
Normal file
66
allergies/README.md
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
# Allergies
|
||||||
|
|
||||||
|
Welcome to Allergies on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
|
||||||
|
|
||||||
|
An allergy test produces a single numeric score which contains the
|
||||||
|
information about all the allergies the person has (that they were
|
||||||
|
tested for).
|
||||||
|
|
||||||
|
The list of items (and their value) that were tested are:
|
||||||
|
|
||||||
|
* eggs (1)
|
||||||
|
* peanuts (2)
|
||||||
|
* shellfish (4)
|
||||||
|
* strawberries (8)
|
||||||
|
* tomatoes (16)
|
||||||
|
* chocolate (32)
|
||||||
|
* pollen (64)
|
||||||
|
* cats (128)
|
||||||
|
|
||||||
|
So if Tom is allergic to peanuts and chocolate, he gets a score of 34.
|
||||||
|
|
||||||
|
Now, given just that score of 34, your program should be able to say:
|
||||||
|
|
||||||
|
- Whether Tom is allergic to any one of those allergens listed above.
|
||||||
|
- All the allergens Tom is allergic to.
|
||||||
|
|
||||||
|
Note: a given score may include allergens **not** listed above (i.e.
|
||||||
|
allergens that score 256, 512, 1024, etc.). Your program should
|
||||||
|
ignore those components of the score. For example, if the allergy
|
||||||
|
score is 257, your program should only report the eggs (1) allergy.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @EduardoBautista
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @ashleygwilliams
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @EduardoBautista
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @IanWhitney
|
||||||
|
- @kytrinyx
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @navossoc
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @taravancil
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Jumpstart Lab Warm-up - http://jumpstartlab.com
|
33
allergies/src/lib.rs
Normal file
33
allergies/src/lib.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
pub struct Allergies;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum Allergen {
|
||||||
|
Eggs,
|
||||||
|
Peanuts,
|
||||||
|
Shellfish,
|
||||||
|
Strawberries,
|
||||||
|
Tomatoes,
|
||||||
|
Chocolate,
|
||||||
|
Pollen,
|
||||||
|
Cats,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Allergies {
|
||||||
|
pub fn new(score: u32) -> Self {
|
||||||
|
unimplemented!(
|
||||||
|
"Given the '{}' score, construct a new Allergies struct.",
|
||||||
|
score
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_allergic_to(&self, allergen: &Allergen) -> bool {
|
||||||
|
unimplemented!(
|
||||||
|
"Determine if the patient is allergic to the '{:?}' allergen.",
|
||||||
|
allergen
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn allergies(&self) -> Vec<Allergen> {
|
||||||
|
unimplemented!("Return the list of allergens contained within the score with which the Allergies struct was made.");
|
||||||
|
}
|
||||||
|
}
|
146
allergies/tests/allergies.rs
Normal file
146
allergies/tests/allergies.rs
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
use allergies::*;
|
||||||
|
|
||||||
|
fn compare_allergy_vectors(expected: &[Allergen], actual: &[Allergen]) {
|
||||||
|
for element in expected {
|
||||||
|
if !actual.contains(element) {
|
||||||
|
panic!(
|
||||||
|
"Allergen missing\n {:?} should be in {:?}",
|
||||||
|
element, actual
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if actual.len() != expected.len() {
|
||||||
|
panic!(
|
||||||
|
"Allergy vectors are of different lengths\n expected {:?}\n got {:?}",
|
||||||
|
expected, actual
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_not_allergic_to_anything() {
|
||||||
|
let allergies = Allergies::new(0);
|
||||||
|
assert!(!allergies.is_allergic_to(&Allergen::Peanuts));
|
||||||
|
assert!(!allergies.is_allergic_to(&Allergen::Cats));
|
||||||
|
assert!(!allergies.is_allergic_to(&Allergen::Strawberries));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn is_allergic_to_eggs() {
|
||||||
|
assert!(Allergies::new(1).is_allergic_to(&Allergen::Eggs));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn is_allergic_to_egg_shellfish_and_strawberries() {
|
||||||
|
let allergies = Allergies::new(5);
|
||||||
|
assert!(allergies.is_allergic_to(&Allergen::Eggs));
|
||||||
|
assert!(allergies.is_allergic_to(&Allergen::Shellfish));
|
||||||
|
assert!(!allergies.is_allergic_to(&Allergen::Strawberries));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn no_allergies_at_all() {
|
||||||
|
let expected = &[];
|
||||||
|
let allergies = Allergies::new(0).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_just_eggs() {
|
||||||
|
let expected = &[Allergen::Eggs];
|
||||||
|
let allergies = Allergies::new(1).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_just_peanuts() {
|
||||||
|
let expected = &[Allergen::Peanuts];
|
||||||
|
let allergies = Allergies::new(2).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_just_strawberries() {
|
||||||
|
let expected = &[Allergen::Strawberries];
|
||||||
|
let allergies = Allergies::new(8).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_eggs_and_peanuts() {
|
||||||
|
let expected = &[Allergen::Eggs, Allergen::Peanuts];
|
||||||
|
let allergies = Allergies::new(3).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_eggs_and_shellfish() {
|
||||||
|
let expected = &[Allergen::Eggs, Allergen::Shellfish];
|
||||||
|
let allergies = Allergies::new(5).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_many_things() {
|
||||||
|
let expected = &[
|
||||||
|
Allergen::Strawberries,
|
||||||
|
Allergen::Tomatoes,
|
||||||
|
Allergen::Chocolate,
|
||||||
|
Allergen::Pollen,
|
||||||
|
Allergen::Cats,
|
||||||
|
];
|
||||||
|
let allergies = Allergies::new(248).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn allergic_to_everything() {
|
||||||
|
let expected = &[
|
||||||
|
Allergen::Eggs,
|
||||||
|
Allergen::Peanuts,
|
||||||
|
Allergen::Shellfish,
|
||||||
|
Allergen::Strawberries,
|
||||||
|
Allergen::Tomatoes,
|
||||||
|
Allergen::Chocolate,
|
||||||
|
Allergen::Pollen,
|
||||||
|
Allergen::Cats,
|
||||||
|
];
|
||||||
|
let allergies = Allergies::new(255).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn scores_over_255_do_not_trigger_false_positives() {
|
||||||
|
let expected = &[
|
||||||
|
Allergen::Eggs,
|
||||||
|
Allergen::Shellfish,
|
||||||
|
Allergen::Strawberries,
|
||||||
|
Allergen::Tomatoes,
|
||||||
|
Allergen::Chocolate,
|
||||||
|
Allergen::Pollen,
|
||||||
|
Allergen::Cats,
|
||||||
|
];
|
||||||
|
let allergies = Allergies::new(509).allergies();
|
||||||
|
|
||||||
|
compare_allergy_vectors(expected, &allergies);
|
||||||
|
}
|
37
alphametics/.exercism/config.json
Normal file
37
alphametics/.exercism/config.json
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
{
|
||||||
|
"blurb": "Write a function to solve alphametics puzzles.",
|
||||||
|
"authors": [
|
||||||
|
"ijanos"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"Baelyk",
|
||||||
|
"ClashTheBunny",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"IanWhitney",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"navossoc",
|
||||||
|
"nfiles",
|
||||||
|
"nikamirrr",
|
||||||
|
"omer-g",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/alphametics.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
1
alphametics/.exercism/metadata.json
Normal file
1
alphametics/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"alphametics","id":"3d23ea86a95e4402a5a0d25c057a4fe7","url":"https://exercism.org/tracks/rust/exercises/alphametics","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
alphametics/.gitignore
vendored
Normal file
8
alphametics/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
alphametics/Cargo.toml
Normal file
4
alphametics/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "alphametics"
|
||||||
|
version = "1.3.0"
|
85
alphametics/HELP.md
Normal file
85
alphametics/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
64
alphametics/README.md
Normal file
64
alphametics/README.md
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
# Alphametics
|
||||||
|
|
||||||
|
Welcome to Alphametics on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Write a function to solve alphametics puzzles.
|
||||||
|
|
||||||
|
[Alphametics](https://en.wikipedia.org/wiki/Alphametics) is a puzzle where
|
||||||
|
letters in words are replaced with numbers.
|
||||||
|
|
||||||
|
For example `SEND + MORE = MONEY`:
|
||||||
|
|
||||||
|
```text
|
||||||
|
S E N D
|
||||||
|
M O R E +
|
||||||
|
-----------
|
||||||
|
M O N E Y
|
||||||
|
```
|
||||||
|
|
||||||
|
Replacing these with valid numbers gives:
|
||||||
|
|
||||||
|
```text
|
||||||
|
9 5 6 7
|
||||||
|
1 0 8 5 +
|
||||||
|
-----------
|
||||||
|
1 0 6 5 2
|
||||||
|
```
|
||||||
|
|
||||||
|
This is correct because every letter is replaced by a different number and the
|
||||||
|
words, translated into numbers, then make a valid sum.
|
||||||
|
|
||||||
|
Each letter must represent a different digit, and the leading digit of
|
||||||
|
a multi-digit number must not be zero.
|
||||||
|
|
||||||
|
Write a function to solve alphametics puzzles.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @ijanos
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @Baelyk
|
||||||
|
- @ClashTheBunny
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @IanWhitney
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @navossoc
|
||||||
|
- @nfiles
|
||||||
|
- @nikamirrr
|
||||||
|
- @omer-g
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
5
alphametics/src/lib.rs
Normal file
5
alphametics/src/lib.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
pub fn solve(input: &str) -> Option<HashMap<char, u8>> {
|
||||||
|
unimplemented!("Solve the alphametic {:?}", input)
|
||||||
|
}
|
125
alphametics/tests/alphametics.rs
Normal file
125
alphametics/tests/alphametics.rs
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn assert_alphametic_solution_eq(puzzle: &str, solution: &[(char, u8)]) {
|
||||||
|
let answer = alphametics::solve(puzzle);
|
||||||
|
let solution: HashMap<char, u8> = solution.iter().cloned().collect();
|
||||||
|
assert_eq!(answer, Some(solution));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_with_three_letters() {
|
||||||
|
assert_alphametic_solution_eq("I + BB == ILL", &[('I', 1), ('B', 9), ('L', 0)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_must_have_unique_value_for_each_letter() {
|
||||||
|
let answer = alphametics::solve("A == B");
|
||||||
|
assert_eq!(answer, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_leading_zero_solution_is_invalid() {
|
||||||
|
let answer = alphametics::solve("ACA + DD == BD");
|
||||||
|
assert_eq!(answer, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn puzzle_with_two_digits_final_carry() {
|
||||||
|
assert_alphametic_solution_eq(
|
||||||
|
"A + A + A + A + A + A + A + A + A + A + A + B == BCC",
|
||||||
|
&[('A', 9), ('B', 1), ('C', 0)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_puzzle_with_four_letters() {
|
||||||
|
assert_alphametic_solution_eq("AS + A == MOM", &[('A', 9), ('S', 2), ('M', 1), ('O', 0)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_puzzle_with_six_letters() {
|
||||||
|
assert_alphametic_solution_eq(
|
||||||
|
"NO + NO + TOO == LATE",
|
||||||
|
&[('N', 7), ('O', 4), ('T', 9), ('L', 1), ('A', 0), ('E', 2)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_puzzle_with_seven_letters() {
|
||||||
|
assert_alphametic_solution_eq(
|
||||||
|
"HE + SEES + THE == LIGHT",
|
||||||
|
&[
|
||||||
|
('E', 4),
|
||||||
|
('G', 2),
|
||||||
|
('H', 5),
|
||||||
|
('I', 0),
|
||||||
|
('L', 1),
|
||||||
|
('S', 9),
|
||||||
|
('T', 7),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_puzzle_with_eight_letters() {
|
||||||
|
assert_alphametic_solution_eq(
|
||||||
|
"SEND + MORE == MONEY",
|
||||||
|
&[
|
||||||
|
('S', 9),
|
||||||
|
('E', 5),
|
||||||
|
('N', 6),
|
||||||
|
('D', 7),
|
||||||
|
('M', 1),
|
||||||
|
('O', 0),
|
||||||
|
('R', 8),
|
||||||
|
('Y', 2),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_puzzle_with_ten_letters() {
|
||||||
|
assert_alphametic_solution_eq(
|
||||||
|
"AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE",
|
||||||
|
&[
|
||||||
|
('A', 5),
|
||||||
|
('D', 3),
|
||||||
|
('E', 4),
|
||||||
|
('F', 7),
|
||||||
|
('G', 8),
|
||||||
|
('N', 0),
|
||||||
|
('O', 2),
|
||||||
|
('R', 1),
|
||||||
|
('S', 6),
|
||||||
|
('T', 9),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_puzzle_with_ten_letters_and_199_addends() {
|
||||||
|
assert_alphametic_solution_eq(
|
||||||
|
"THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE + THE + TROLL + RESTS + AT + THE + HOLE + OF + LOSSES + IT + IS + THERE + THAT + SHE + STORES + ROLES + OF + LEATHERS + AFTER + SHE + SATISFIES + HER + HATE + OFF + THOSE + FEARS + A + TASTE + RISES + AS + SHE + HEARS + THE + LEAST + FAR + HORSE + THOSE + FAST + HORSES + THAT + FIRST + HEAR + THE + TROLL + FLEE + OFF + TO + THE + FOREST + THE + HORSES + THAT + ALERTS + RAISE + THE + STARES + OF + THE + OTHERS + AS + THE + TROLL + ASSAILS + AT + THE + TOTAL + SHIFT + HER + TEETH + TEAR + HOOF + OFF + TORSO + AS + THE + LAST + HORSE + FORFEITS + ITS + LIFE + THE + FIRST + FATHERS + HEAR + OF + THE + HORRORS + THEIR + FEARS + THAT + THE + FIRES + FOR + THEIR + FEASTS + ARREST + AS + THE + FIRST + FATHERS + RESETTLE + THE + LAST + OF + THE + FIRE + HORSES + THE + LAST + TROLL + HARASSES + THE + FOREST + HEART + FREE + AT + LAST + OF + THE + LAST + TROLL + ALL + OFFER + THEIR + FIRE + HEAT + TO + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A + ROOFS + FOR + THEIR + SAFE == FORTRESSES",
|
||||||
|
&[
|
||||||
|
('A', 1),
|
||||||
|
('E', 0),
|
||||||
|
('F', 5),
|
||||||
|
('H', 8),
|
||||||
|
('I', 7),
|
||||||
|
('L', 2),
|
||||||
|
('O', 6),
|
||||||
|
('R', 3),
|
||||||
|
('S', 4),
|
||||||
|
('T', 9),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
46
anagram/.exercism/config.json
Normal file
46
anagram/.exercism/config.json
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"blurb": "Given a word and a list of possible anagrams, select the correct sublist.",
|
||||||
|
"authors": [
|
||||||
|
"EduardoBautista"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"andrewclarkson",
|
||||||
|
"ashleygwilliams",
|
||||||
|
"bobahop",
|
||||||
|
"chancancode",
|
||||||
|
"ClashTheBunny",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"Dimkar3000",
|
||||||
|
"EduardoBautista",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"gris",
|
||||||
|
"IanWhitney",
|
||||||
|
"kytrinyx",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"pminten",
|
||||||
|
"quartsize",
|
||||||
|
"rofrol",
|
||||||
|
"stevejb71",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/anagram.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Inspired by the Extreme Startup game",
|
||||||
|
"source_url": "https://github.com/rchatley/extreme_startup"
|
||||||
|
}
|
1
anagram/.exercism/metadata.json
Normal file
1
anagram/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"anagram","id":"771865a2d31140989a6bb940b647e554","url":"https://exercism.org/tracks/rust/exercises/anagram","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
anagram/.gitignore
vendored
Normal file
8
anagram/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
anagram/Cargo.toml
Normal file
4
anagram/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "anagram"
|
||||||
|
version = "0.0.0"
|
85
anagram/HELP.md
Normal file
85
anagram/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
61
anagram/README.md
Normal file
61
anagram/README.md
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
# Anagram
|
||||||
|
|
||||||
|
Welcome to Anagram on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
An anagram is a rearrangement of letters to form a new word.
|
||||||
|
Given a word and a list of candidates, select the sublist of anagrams of the given word.
|
||||||
|
|
||||||
|
Given `"listen"` and a list of candidates like `"enlists" "google"
|
||||||
|
"inlets" "banana"` the program should return a list containing
|
||||||
|
`"inlets"`.
|
||||||
|
|
||||||
|
The solution is case insensitive, which means `"WOrd"` is the same as `"word"` or `"woRd"`. It may help to take a peek at the [std library](https://doc.rust-lang.org/std/primitive.char.html) for functions that can convert between them.
|
||||||
|
|
||||||
|
The solution cannot contain the input word. A word is always an anagram of itself, which means it is not an interesting result. Given `"hello"` and the list `["hello", "olleh"]` the answer is `["olleh"]`.
|
||||||
|
|
||||||
|
You are going to have to adjust the function signature provided in the stub in order for the lifetimes to work out properly. This is intentional: what's there demonstrates the basics of lifetime syntax, and what's missing teaches how to interpret lifetime-related compiler errors.
|
||||||
|
|
||||||
|
Try to limit case changes. Case changes are expensive in terms of time, so it's faster to minimize them.
|
||||||
|
|
||||||
|
If sorting, consider [sort_unstable](https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable) which is typically faster than stable sorting. When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn't allocate auxiliary memory.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @EduardoBautista
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @andrewclarkson
|
||||||
|
- @ashleygwilliams
|
||||||
|
- @bobahop
|
||||||
|
- @chancancode
|
||||||
|
- @ClashTheBunny
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @Dimkar3000
|
||||||
|
- @EduardoBautista
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @gris
|
||||||
|
- @IanWhitney
|
||||||
|
- @kytrinyx
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @pminten
|
||||||
|
- @quartsize
|
||||||
|
- @rofrol
|
||||||
|
- @stevejb71
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup
|
9
anagram/src/lib.rs
Normal file
9
anagram/src/lib.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&str]) -> HashSet<&'a str> {
|
||||||
|
unimplemented!(
|
||||||
|
"For the '{}' word find anagrams among the following words: {:?}",
|
||||||
|
word,
|
||||||
|
possible_anagrams
|
||||||
|
);
|
||||||
|
}
|
186
anagram/tests/anagram.rs
Normal file
186
anagram/tests/anagram.rs
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
fn process_anagram_case(word: &str, inputs: &[&str], expected: &[&str]) {
|
||||||
|
let result = anagram::anagrams_for(word, inputs);
|
||||||
|
|
||||||
|
let expected: HashSet<&str> = expected.iter().cloned().collect();
|
||||||
|
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_no_matches() {
|
||||||
|
let word = "diaper";
|
||||||
|
|
||||||
|
let inputs = ["hello", "world", "zombies", "pants"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_detect_simple_anagram() {
|
||||||
|
let word = "ant";
|
||||||
|
|
||||||
|
let inputs = ["tan", "stand", "at"];
|
||||||
|
|
||||||
|
let outputs = vec!["tan"];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_does_not_confuse_different_duplicates() {
|
||||||
|
let word = "galea";
|
||||||
|
|
||||||
|
let inputs = ["eagle"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_eliminate_anagram_subsets() {
|
||||||
|
let word = "good";
|
||||||
|
|
||||||
|
let inputs = ["dog", "goody"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_detect_anagram() {
|
||||||
|
let word = "listen";
|
||||||
|
|
||||||
|
let inputs = ["enlists", "google", "inlets", "banana"];
|
||||||
|
|
||||||
|
let outputs = vec!["inlets"];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_multiple_anagrams() {
|
||||||
|
let word = "allergy";
|
||||||
|
|
||||||
|
let inputs = [
|
||||||
|
"gallery",
|
||||||
|
"ballerina",
|
||||||
|
"regally",
|
||||||
|
"clergy",
|
||||||
|
"largely",
|
||||||
|
"leading",
|
||||||
|
];
|
||||||
|
|
||||||
|
let outputs = vec!["gallery", "regally", "largely"];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_case_insensitive_anagrams() {
|
||||||
|
let word = "Orchestra";
|
||||||
|
|
||||||
|
let inputs = ["cashregister", "Carthorse", "radishes"];
|
||||||
|
|
||||||
|
let outputs = vec!["Carthorse"];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_unicode_anagrams() {
|
||||||
|
let word = "ΑΒΓ";
|
||||||
|
|
||||||
|
// These words don't make sense, they're just greek letters cobbled together.
|
||||||
|
let inputs = ["ΒΓΑ", "ΒΓΔ", "γβα"];
|
||||||
|
|
||||||
|
let outputs = vec!["ΒΓΑ", "γβα"];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_misleading_unicode_anagrams() {
|
||||||
|
// Despite what a human might think these words contain different letters, the input uses Greek
|
||||||
|
// A and B while the list of potential anagrams uses Latin A and B.
|
||||||
|
let word = "ΑΒΓ";
|
||||||
|
|
||||||
|
let inputs = ["ABΓ"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_does_not_detect_a_word_as_its_own_anagram() {
|
||||||
|
let word = "banana";
|
||||||
|
|
||||||
|
let inputs = ["banana"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_does_not_detect_a_differently_cased_word_as_its_own_anagram() {
|
||||||
|
let word = "banana";
|
||||||
|
|
||||||
|
let inputs = ["bAnana"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_does_not_detect_a_differently_cased_unicode_word_as_its_own_anagram() {
|
||||||
|
let word = "ΑΒΓ";
|
||||||
|
|
||||||
|
let inputs = ["ΑΒγ"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_same_bytes_different_chars() {
|
||||||
|
let word = "a⬂"; // 61 E2 AC 82
|
||||||
|
|
||||||
|
let inputs = ["€a"]; // E2 82 AC 61
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_different_words_but_same_ascii_sum() {
|
||||||
|
let word = "bc";
|
||||||
|
|
||||||
|
let inputs = ["ad"];
|
||||||
|
|
||||||
|
let outputs = vec![];
|
||||||
|
|
||||||
|
process_anagram_case(word, &inputs, &outputs);
|
||||||
|
}
|
35
armstrong-numbers/.exercism/config.json
Normal file
35
armstrong-numbers/.exercism/config.json
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"blurb": "Determine if a number is an Armstrong number",
|
||||||
|
"authors": [
|
||||||
|
"shingtaklam1324"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"AndrewKvalheim",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"eddyp",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"lutostag",
|
||||||
|
"ocstl",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"sputnick1124",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/armstrong-numbers.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Wikipedia",
|
||||||
|
"source_url": "https://en.wikipedia.org/wiki/Narcissistic_number"
|
||||||
|
}
|
1
armstrong-numbers/.exercism/metadata.json
Normal file
1
armstrong-numbers/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"armstrong-numbers","id":"3464de1f14f74cab92f634b3a35cf8e6","url":"https://exercism.org/tracks/rust/exercises/armstrong-numbers","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
armstrong-numbers/.gitignore
vendored
Normal file
8
armstrong-numbers/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
armstrong-numbers/Cargo.toml
Normal file
4
armstrong-numbers/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "armstrong_numbers"
|
||||||
|
version = "1.1.0"
|
85
armstrong-numbers/HELP.md
Normal file
85
armstrong-numbers/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
44
armstrong-numbers/README.md
Normal file
44
armstrong-numbers/README.md
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# Armstrong Numbers
|
||||||
|
|
||||||
|
Welcome to Armstrong Numbers on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
- 9 is an Armstrong number, because `9 = 9^1 = 9`
|
||||||
|
- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1`
|
||||||
|
- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153`
|
||||||
|
- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`
|
||||||
|
|
||||||
|
Write some code to determine whether a number is an Armstrong number.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @shingtaklam1324
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @AndrewKvalheim
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @eddyp
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @lutostag
|
||||||
|
- @ocstl
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @sputnick1124
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Wikipedia - https://en.wikipedia.org/wiki/Narcissistic_number
|
3
armstrong-numbers/src/lib.rs
Normal file
3
armstrong-numbers/src/lib.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn is_armstrong_number(num: u32) -> bool {
|
||||||
|
unimplemented!("true if {} is an armstrong number", num)
|
||||||
|
}
|
54
armstrong-numbers/tests/armstrong-numbers.rs
Normal file
54
armstrong-numbers/tests/armstrong-numbers.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use armstrong_numbers::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_zero_is_an_armstrong_number() {
|
||||||
|
assert!(is_armstrong_number(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_single_digit_numbers_are_armstrong_numbers() {
|
||||||
|
assert!(is_armstrong_number(5))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_there_are_no_2_digit_armstrong_numbers() {
|
||||||
|
assert!(!is_armstrong_number(10))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_three_digit_armstrong_number() {
|
||||||
|
assert!(is_armstrong_number(153))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_three_digit_non_armstrong_number() {
|
||||||
|
assert!(!is_armstrong_number(100))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_four_digit_armstrong_number() {
|
||||||
|
assert!(is_armstrong_number(9474))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_four_digit_non_armstrong_number() {
|
||||||
|
assert!(!is_armstrong_number(9475))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_seven_digit_armstrong_number() {
|
||||||
|
assert!(is_armstrong_number(9_926_315))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_seven_digit_non_armstrong_number() {
|
||||||
|
assert!(!is_armstrong_number(9_926_316))
|
||||||
|
}
|
38
atbash-cipher/.exercism/config.json
Normal file
38
atbash-cipher/.exercism/config.json
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.",
|
||||||
|
"authors": [
|
||||||
|
"nikhilshagri"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"AvasDream",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"IanWhitney",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"navossoc",
|
||||||
|
"nfiles",
|
||||||
|
"nikhilshagri",
|
||||||
|
"ocstl",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"vadimkerr",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/atbash-cipher.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Wikipedia",
|
||||||
|
"source_url": "http://en.wikipedia.org/wiki/Atbash"
|
||||||
|
}
|
1
atbash-cipher/.exercism/metadata.json
Normal file
1
atbash-cipher/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"atbash-cipher","id":"607bc341734948ce9af2cfe5511bad3f","url":"https://exercism.org/tracks/rust/exercises/atbash-cipher","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
atbash-cipher/.gitignore
vendored
Normal file
8
atbash-cipher/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
atbash-cipher/Cargo.toml
Normal file
4
atbash-cipher/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "atbash-cipher"
|
||||||
|
version = "1.2.0"
|
85
atbash-cipher/HELP.md
Normal file
85
atbash-cipher/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
64
atbash-cipher/README.md
Normal file
64
atbash-cipher/README.md
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
# Atbash Cipher
|
||||||
|
|
||||||
|
Welcome to Atbash Cipher on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
|
||||||
|
|
||||||
|
The Atbash cipher is a simple substitution cipher that relies on
|
||||||
|
transposing all the letters in the alphabet such that the resulting
|
||||||
|
alphabet is backwards. The first letter is replaced with the last
|
||||||
|
letter, the second with the second-last, and so on.
|
||||||
|
|
||||||
|
An Atbash cipher for the Latin alphabet would be as follows:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Plain: abcdefghijklmnopqrstuvwxyz
|
||||||
|
Cipher: zyxwvutsrqponmlkjihgfedcba
|
||||||
|
```
|
||||||
|
|
||||||
|
It is a very weak cipher because it only has one possible key, and it is
|
||||||
|
a simple monoalphabetic substitution cipher. However, this may not have
|
||||||
|
been an issue in the cipher's time.
|
||||||
|
|
||||||
|
Ciphertext is written out in groups of fixed length, the traditional group size
|
||||||
|
being 5 letters, and punctuation is excluded. This is to make it harder to guess
|
||||||
|
things based on word boundaries.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
- Encoding `test` gives `gvhg`
|
||||||
|
- Decoding `gvhg` gives `test`
|
||||||
|
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @nikhilshagri
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @AvasDream
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @IanWhitney
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @navossoc
|
||||||
|
- @nfiles
|
||||||
|
- @nikhilshagri
|
||||||
|
- @ocstl
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @vadimkerr
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Wikipedia - http://en.wikipedia.org/wiki/Atbash
|
9
atbash-cipher/src/lib.rs
Normal file
9
atbash-cipher/src/lib.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/// "Encipher" with the Atbash cipher.
|
||||||
|
pub fn encode(plain: &str) -> String {
|
||||||
|
unimplemented!("Encoding of {:?} in Atbash cipher.", plain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// "Decipher" with the Atbash cipher.
|
||||||
|
pub fn decode(cipher: &str) -> String {
|
||||||
|
unimplemented!("Decoding of {:?} in Atbash cipher.", cipher);
|
||||||
|
}
|
99
atbash-cipher/tests/atbash-cipher.rs
Normal file
99
atbash-cipher/tests/atbash-cipher.rs
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
use atbash_cipher as cipher;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_encode_yes() {
|
||||||
|
assert_eq!(cipher::encode("yes"), "bvh");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_no() {
|
||||||
|
assert_eq!(cipher::encode("no"), "ml");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_omg() {
|
||||||
|
assert_eq!(cipher::encode("OMG"), "lnt");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_spaces() {
|
||||||
|
assert_eq!(cipher::encode("O M G"), "lnt");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_mindblowingly() {
|
||||||
|
assert_eq!(cipher::encode("mindblowingly"), "nrmwy oldrm tob");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_numbers() {
|
||||||
|
assert_eq!(
|
||||||
|
cipher::encode("Testing,1 2 3, testing."),
|
||||||
|
"gvhgr mt123 gvhgr mt"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_deep_thought() {
|
||||||
|
assert_eq!(cipher::encode("Truth is fiction."), "gifgs rhurx grlm");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_encode_all_the_letters() {
|
||||||
|
assert_eq!(
|
||||||
|
cipher::encode("The quick brown fox jumps over the lazy dog."),
|
||||||
|
"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_decode_exercism() {
|
||||||
|
assert_eq!(cipher::decode("vcvix rhn"), "exercism");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_decode_a_sentence() {
|
||||||
|
assert_eq!(
|
||||||
|
cipher::decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"),
|
||||||
|
"anobstacleisoftenasteppingstone"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_decode_numbers() {
|
||||||
|
assert_eq!(cipher::decode("gvhgr mt123 gvhgr mt"), "testing123testing");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_decode_all_the_letters() {
|
||||||
|
assert_eq!(
|
||||||
|
cipher::decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"),
|
||||||
|
"thequickbrownfoxjumpsoverthelazydog"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_decode_with_too_many_spaces() {
|
||||||
|
assert_eq!(cipher::decode("vc vix r hn"), "exercism");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_decode_with_no_spaces() {
|
||||||
|
assert_eq!(
|
||||||
|
cipher::decode("zmlyhgzxovrhlugvmzhgvkkrmthglmv"),
|
||||||
|
"anobstacleisoftenasteppingstone",
|
||||||
|
);
|
||||||
|
}
|
43
beer-song/.exercism/config.json
Normal file
43
beer-song/.exercism/config.json
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"blurb": "Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.",
|
||||||
|
"authors": [
|
||||||
|
"EduardoBautista"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"andrewclarkson",
|
||||||
|
"ashleygwilliams",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"EduardoBautista",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"IanWhitney",
|
||||||
|
"kytrinyx",
|
||||||
|
"leoyvens",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"murlakatamenka",
|
||||||
|
"navossoc",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"pminten",
|
||||||
|
"razielgn",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/beer-song.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Learn to Program by Chris Pine",
|
||||||
|
"source_url": "http://pine.fm/LearnToProgram/?Chapter=06"
|
||||||
|
}
|
1
beer-song/.exercism/metadata.json
Normal file
1
beer-song/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"beer-song","id":"b6de10fcef45484484208227bf9c7c2b","url":"https://exercism.org/tracks/rust/exercises/beer-song","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
beer-song/.gitignore
vendored
Normal file
8
beer-song/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
beer-song/Cargo.toml
Normal file
4
beer-song/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "beer-song"
|
||||||
|
version = "0.0.0"
|
85
beer-song/HELP.md
Normal file
85
beer-song/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
361
beer-song/README.md
Normal file
361
beer-song/README.md
Normal file
|
@ -0,0 +1,361 @@
|
||||||
|
# Beer Song
|
||||||
|
|
||||||
|
Welcome to Beer Song on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Recite the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
|
||||||
|
|
||||||
|
Note that not all verses are identical.
|
||||||
|
|
||||||
|
```text
|
||||||
|
99 bottles of beer on the wall, 99 bottles of beer.
|
||||||
|
Take one down and pass it around, 98 bottles of beer on the wall.
|
||||||
|
|
||||||
|
98 bottles of beer on the wall, 98 bottles of beer.
|
||||||
|
Take one down and pass it around, 97 bottles of beer on the wall.
|
||||||
|
|
||||||
|
97 bottles of beer on the wall, 97 bottles of beer.
|
||||||
|
Take one down and pass it around, 96 bottles of beer on the wall.
|
||||||
|
|
||||||
|
96 bottles of beer on the wall, 96 bottles of beer.
|
||||||
|
Take one down and pass it around, 95 bottles of beer on the wall.
|
||||||
|
|
||||||
|
95 bottles of beer on the wall, 95 bottles of beer.
|
||||||
|
Take one down and pass it around, 94 bottles of beer on the wall.
|
||||||
|
|
||||||
|
94 bottles of beer on the wall, 94 bottles of beer.
|
||||||
|
Take one down and pass it around, 93 bottles of beer on the wall.
|
||||||
|
|
||||||
|
93 bottles of beer on the wall, 93 bottles of beer.
|
||||||
|
Take one down and pass it around, 92 bottles of beer on the wall.
|
||||||
|
|
||||||
|
92 bottles of beer on the wall, 92 bottles of beer.
|
||||||
|
Take one down and pass it around, 91 bottles of beer on the wall.
|
||||||
|
|
||||||
|
91 bottles of beer on the wall, 91 bottles of beer.
|
||||||
|
Take one down and pass it around, 90 bottles of beer on the wall.
|
||||||
|
|
||||||
|
90 bottles of beer on the wall, 90 bottles of beer.
|
||||||
|
Take one down and pass it around, 89 bottles of beer on the wall.
|
||||||
|
|
||||||
|
89 bottles of beer on the wall, 89 bottles of beer.
|
||||||
|
Take one down and pass it around, 88 bottles of beer on the wall.
|
||||||
|
|
||||||
|
88 bottles of beer on the wall, 88 bottles of beer.
|
||||||
|
Take one down and pass it around, 87 bottles of beer on the wall.
|
||||||
|
|
||||||
|
87 bottles of beer on the wall, 87 bottles of beer.
|
||||||
|
Take one down and pass it around, 86 bottles of beer on the wall.
|
||||||
|
|
||||||
|
86 bottles of beer on the wall, 86 bottles of beer.
|
||||||
|
Take one down and pass it around, 85 bottles of beer on the wall.
|
||||||
|
|
||||||
|
85 bottles of beer on the wall, 85 bottles of beer.
|
||||||
|
Take one down and pass it around, 84 bottles of beer on the wall.
|
||||||
|
|
||||||
|
84 bottles of beer on the wall, 84 bottles of beer.
|
||||||
|
Take one down and pass it around, 83 bottles of beer on the wall.
|
||||||
|
|
||||||
|
83 bottles of beer on the wall, 83 bottles of beer.
|
||||||
|
Take one down and pass it around, 82 bottles of beer on the wall.
|
||||||
|
|
||||||
|
82 bottles of beer on the wall, 82 bottles of beer.
|
||||||
|
Take one down and pass it around, 81 bottles of beer on the wall.
|
||||||
|
|
||||||
|
81 bottles of beer on the wall, 81 bottles of beer.
|
||||||
|
Take one down and pass it around, 80 bottles of beer on the wall.
|
||||||
|
|
||||||
|
80 bottles of beer on the wall, 80 bottles of beer.
|
||||||
|
Take one down and pass it around, 79 bottles of beer on the wall.
|
||||||
|
|
||||||
|
79 bottles of beer on the wall, 79 bottles of beer.
|
||||||
|
Take one down and pass it around, 78 bottles of beer on the wall.
|
||||||
|
|
||||||
|
78 bottles of beer on the wall, 78 bottles of beer.
|
||||||
|
Take one down and pass it around, 77 bottles of beer on the wall.
|
||||||
|
|
||||||
|
77 bottles of beer on the wall, 77 bottles of beer.
|
||||||
|
Take one down and pass it around, 76 bottles of beer on the wall.
|
||||||
|
|
||||||
|
76 bottles of beer on the wall, 76 bottles of beer.
|
||||||
|
Take one down and pass it around, 75 bottles of beer on the wall.
|
||||||
|
|
||||||
|
75 bottles of beer on the wall, 75 bottles of beer.
|
||||||
|
Take one down and pass it around, 74 bottles of beer on the wall.
|
||||||
|
|
||||||
|
74 bottles of beer on the wall, 74 bottles of beer.
|
||||||
|
Take one down and pass it around, 73 bottles of beer on the wall.
|
||||||
|
|
||||||
|
73 bottles of beer on the wall, 73 bottles of beer.
|
||||||
|
Take one down and pass it around, 72 bottles of beer on the wall.
|
||||||
|
|
||||||
|
72 bottles of beer on the wall, 72 bottles of beer.
|
||||||
|
Take one down and pass it around, 71 bottles of beer on the wall.
|
||||||
|
|
||||||
|
71 bottles of beer on the wall, 71 bottles of beer.
|
||||||
|
Take one down and pass it around, 70 bottles of beer on the wall.
|
||||||
|
|
||||||
|
70 bottles of beer on the wall, 70 bottles of beer.
|
||||||
|
Take one down and pass it around, 69 bottles of beer on the wall.
|
||||||
|
|
||||||
|
69 bottles of beer on the wall, 69 bottles of beer.
|
||||||
|
Take one down and pass it around, 68 bottles of beer on the wall.
|
||||||
|
|
||||||
|
68 bottles of beer on the wall, 68 bottles of beer.
|
||||||
|
Take one down and pass it around, 67 bottles of beer on the wall.
|
||||||
|
|
||||||
|
67 bottles of beer on the wall, 67 bottles of beer.
|
||||||
|
Take one down and pass it around, 66 bottles of beer on the wall.
|
||||||
|
|
||||||
|
66 bottles of beer on the wall, 66 bottles of beer.
|
||||||
|
Take one down and pass it around, 65 bottles of beer on the wall.
|
||||||
|
|
||||||
|
65 bottles of beer on the wall, 65 bottles of beer.
|
||||||
|
Take one down and pass it around, 64 bottles of beer on the wall.
|
||||||
|
|
||||||
|
64 bottles of beer on the wall, 64 bottles of beer.
|
||||||
|
Take one down and pass it around, 63 bottles of beer on the wall.
|
||||||
|
|
||||||
|
63 bottles of beer on the wall, 63 bottles of beer.
|
||||||
|
Take one down and pass it around, 62 bottles of beer on the wall.
|
||||||
|
|
||||||
|
62 bottles of beer on the wall, 62 bottles of beer.
|
||||||
|
Take one down and pass it around, 61 bottles of beer on the wall.
|
||||||
|
|
||||||
|
61 bottles of beer on the wall, 61 bottles of beer.
|
||||||
|
Take one down and pass it around, 60 bottles of beer on the wall.
|
||||||
|
|
||||||
|
60 bottles of beer on the wall, 60 bottles of beer.
|
||||||
|
Take one down and pass it around, 59 bottles of beer on the wall.
|
||||||
|
|
||||||
|
59 bottles of beer on the wall, 59 bottles of beer.
|
||||||
|
Take one down and pass it around, 58 bottles of beer on the wall.
|
||||||
|
|
||||||
|
58 bottles of beer on the wall, 58 bottles of beer.
|
||||||
|
Take one down and pass it around, 57 bottles of beer on the wall.
|
||||||
|
|
||||||
|
57 bottles of beer on the wall, 57 bottles of beer.
|
||||||
|
Take one down and pass it around, 56 bottles of beer on the wall.
|
||||||
|
|
||||||
|
56 bottles of beer on the wall, 56 bottles of beer.
|
||||||
|
Take one down and pass it around, 55 bottles of beer on the wall.
|
||||||
|
|
||||||
|
55 bottles of beer on the wall, 55 bottles of beer.
|
||||||
|
Take one down and pass it around, 54 bottles of beer on the wall.
|
||||||
|
|
||||||
|
54 bottles of beer on the wall, 54 bottles of beer.
|
||||||
|
Take one down and pass it around, 53 bottles of beer on the wall.
|
||||||
|
|
||||||
|
53 bottles of beer on the wall, 53 bottles of beer.
|
||||||
|
Take one down and pass it around, 52 bottles of beer on the wall.
|
||||||
|
|
||||||
|
52 bottles of beer on the wall, 52 bottles of beer.
|
||||||
|
Take one down and pass it around, 51 bottles of beer on the wall.
|
||||||
|
|
||||||
|
51 bottles of beer on the wall, 51 bottles of beer.
|
||||||
|
Take one down and pass it around, 50 bottles of beer on the wall.
|
||||||
|
|
||||||
|
50 bottles of beer on the wall, 50 bottles of beer.
|
||||||
|
Take one down and pass it around, 49 bottles of beer on the wall.
|
||||||
|
|
||||||
|
49 bottles of beer on the wall, 49 bottles of beer.
|
||||||
|
Take one down and pass it around, 48 bottles of beer on the wall.
|
||||||
|
|
||||||
|
48 bottles of beer on the wall, 48 bottles of beer.
|
||||||
|
Take one down and pass it around, 47 bottles of beer on the wall.
|
||||||
|
|
||||||
|
47 bottles of beer on the wall, 47 bottles of beer.
|
||||||
|
Take one down and pass it around, 46 bottles of beer on the wall.
|
||||||
|
|
||||||
|
46 bottles of beer on the wall, 46 bottles of beer.
|
||||||
|
Take one down and pass it around, 45 bottles of beer on the wall.
|
||||||
|
|
||||||
|
45 bottles of beer on the wall, 45 bottles of beer.
|
||||||
|
Take one down and pass it around, 44 bottles of beer on the wall.
|
||||||
|
|
||||||
|
44 bottles of beer on the wall, 44 bottles of beer.
|
||||||
|
Take one down and pass it around, 43 bottles of beer on the wall.
|
||||||
|
|
||||||
|
43 bottles of beer on the wall, 43 bottles of beer.
|
||||||
|
Take one down and pass it around, 42 bottles of beer on the wall.
|
||||||
|
|
||||||
|
42 bottles of beer on the wall, 42 bottles of beer.
|
||||||
|
Take one down and pass it around, 41 bottles of beer on the wall.
|
||||||
|
|
||||||
|
41 bottles of beer on the wall, 41 bottles of beer.
|
||||||
|
Take one down and pass it around, 40 bottles of beer on the wall.
|
||||||
|
|
||||||
|
40 bottles of beer on the wall, 40 bottles of beer.
|
||||||
|
Take one down and pass it around, 39 bottles of beer on the wall.
|
||||||
|
|
||||||
|
39 bottles of beer on the wall, 39 bottles of beer.
|
||||||
|
Take one down and pass it around, 38 bottles of beer on the wall.
|
||||||
|
|
||||||
|
38 bottles of beer on the wall, 38 bottles of beer.
|
||||||
|
Take one down and pass it around, 37 bottles of beer on the wall.
|
||||||
|
|
||||||
|
37 bottles of beer on the wall, 37 bottles of beer.
|
||||||
|
Take one down and pass it around, 36 bottles of beer on the wall.
|
||||||
|
|
||||||
|
36 bottles of beer on the wall, 36 bottles of beer.
|
||||||
|
Take one down and pass it around, 35 bottles of beer on the wall.
|
||||||
|
|
||||||
|
35 bottles of beer on the wall, 35 bottles of beer.
|
||||||
|
Take one down and pass it around, 34 bottles of beer on the wall.
|
||||||
|
|
||||||
|
34 bottles of beer on the wall, 34 bottles of beer.
|
||||||
|
Take one down and pass it around, 33 bottles of beer on the wall.
|
||||||
|
|
||||||
|
33 bottles of beer on the wall, 33 bottles of beer.
|
||||||
|
Take one down and pass it around, 32 bottles of beer on the wall.
|
||||||
|
|
||||||
|
32 bottles of beer on the wall, 32 bottles of beer.
|
||||||
|
Take one down and pass it around, 31 bottles of beer on the wall.
|
||||||
|
|
||||||
|
31 bottles of beer on the wall, 31 bottles of beer.
|
||||||
|
Take one down and pass it around, 30 bottles of beer on the wall.
|
||||||
|
|
||||||
|
30 bottles of beer on the wall, 30 bottles of beer.
|
||||||
|
Take one down and pass it around, 29 bottles of beer on the wall.
|
||||||
|
|
||||||
|
29 bottles of beer on the wall, 29 bottles of beer.
|
||||||
|
Take one down and pass it around, 28 bottles of beer on the wall.
|
||||||
|
|
||||||
|
28 bottles of beer on the wall, 28 bottles of beer.
|
||||||
|
Take one down and pass it around, 27 bottles of beer on the wall.
|
||||||
|
|
||||||
|
27 bottles of beer on the wall, 27 bottles of beer.
|
||||||
|
Take one down and pass it around, 26 bottles of beer on the wall.
|
||||||
|
|
||||||
|
26 bottles of beer on the wall, 26 bottles of beer.
|
||||||
|
Take one down and pass it around, 25 bottles of beer on the wall.
|
||||||
|
|
||||||
|
25 bottles of beer on the wall, 25 bottles of beer.
|
||||||
|
Take one down and pass it around, 24 bottles of beer on the wall.
|
||||||
|
|
||||||
|
24 bottles of beer on the wall, 24 bottles of beer.
|
||||||
|
Take one down and pass it around, 23 bottles of beer on the wall.
|
||||||
|
|
||||||
|
23 bottles of beer on the wall, 23 bottles of beer.
|
||||||
|
Take one down and pass it around, 22 bottles of beer on the wall.
|
||||||
|
|
||||||
|
22 bottles of beer on the wall, 22 bottles of beer.
|
||||||
|
Take one down and pass it around, 21 bottles of beer on the wall.
|
||||||
|
|
||||||
|
21 bottles of beer on the wall, 21 bottles of beer.
|
||||||
|
Take one down and pass it around, 20 bottles of beer on the wall.
|
||||||
|
|
||||||
|
20 bottles of beer on the wall, 20 bottles of beer.
|
||||||
|
Take one down and pass it around, 19 bottles of beer on the wall.
|
||||||
|
|
||||||
|
19 bottles of beer on the wall, 19 bottles of beer.
|
||||||
|
Take one down and pass it around, 18 bottles of beer on the wall.
|
||||||
|
|
||||||
|
18 bottles of beer on the wall, 18 bottles of beer.
|
||||||
|
Take one down and pass it around, 17 bottles of beer on the wall.
|
||||||
|
|
||||||
|
17 bottles of beer on the wall, 17 bottles of beer.
|
||||||
|
Take one down and pass it around, 16 bottles of beer on the wall.
|
||||||
|
|
||||||
|
16 bottles of beer on the wall, 16 bottles of beer.
|
||||||
|
Take one down and pass it around, 15 bottles of beer on the wall.
|
||||||
|
|
||||||
|
15 bottles of beer on the wall, 15 bottles of beer.
|
||||||
|
Take one down and pass it around, 14 bottles of beer on the wall.
|
||||||
|
|
||||||
|
14 bottles of beer on the wall, 14 bottles of beer.
|
||||||
|
Take one down and pass it around, 13 bottles of beer on the wall.
|
||||||
|
|
||||||
|
13 bottles of beer on the wall, 13 bottles of beer.
|
||||||
|
Take one down and pass it around, 12 bottles of beer on the wall.
|
||||||
|
|
||||||
|
12 bottles of beer on the wall, 12 bottles of beer.
|
||||||
|
Take one down and pass it around, 11 bottles of beer on the wall.
|
||||||
|
|
||||||
|
11 bottles of beer on the wall, 11 bottles of beer.
|
||||||
|
Take one down and pass it around, 10 bottles of beer on the wall.
|
||||||
|
|
||||||
|
10 bottles of beer on the wall, 10 bottles of beer.
|
||||||
|
Take one down and pass it around, 9 bottles of beer on the wall.
|
||||||
|
|
||||||
|
9 bottles of beer on the wall, 9 bottles of beer.
|
||||||
|
Take one down and pass it around, 8 bottles of beer on the wall.
|
||||||
|
|
||||||
|
8 bottles of beer on the wall, 8 bottles of beer.
|
||||||
|
Take one down and pass it around, 7 bottles of beer on the wall.
|
||||||
|
|
||||||
|
7 bottles of beer on the wall, 7 bottles of beer.
|
||||||
|
Take one down and pass it around, 6 bottles of beer on the wall.
|
||||||
|
|
||||||
|
6 bottles of beer on the wall, 6 bottles of beer.
|
||||||
|
Take one down and pass it around, 5 bottles of beer on the wall.
|
||||||
|
|
||||||
|
5 bottles of beer on the wall, 5 bottles of beer.
|
||||||
|
Take one down and pass it around, 4 bottles of beer on the wall.
|
||||||
|
|
||||||
|
4 bottles of beer on the wall, 4 bottles of beer.
|
||||||
|
Take one down and pass it around, 3 bottles of beer on the wall.
|
||||||
|
|
||||||
|
3 bottles of beer on the wall, 3 bottles of beer.
|
||||||
|
Take one down and pass it around, 2 bottles of beer on the wall.
|
||||||
|
|
||||||
|
2 bottles of beer on the wall, 2 bottles of beer.
|
||||||
|
Take one down and pass it around, 1 bottle of beer on the wall.
|
||||||
|
|
||||||
|
1 bottle of beer on the wall, 1 bottle of beer.
|
||||||
|
Take it down and pass it around, no more bottles of beer on the wall.
|
||||||
|
|
||||||
|
No more bottles of beer on the wall, no more bottles of beer.
|
||||||
|
Go to the store and buy some more, 99 bottles of beer on the wall.
|
||||||
|
```
|
||||||
|
|
||||||
|
## For bonus points
|
||||||
|
|
||||||
|
Did you get the tests passing and the code clean? If you want to, these
|
||||||
|
are some additional things you could try:
|
||||||
|
|
||||||
|
* Remove as much duplication as you possibly can.
|
||||||
|
* Optimize for readability, even if it means introducing duplication.
|
||||||
|
* If you've removed all the duplication, do you have a lot of
|
||||||
|
conditionals? Try replacing the conditionals with polymorphism, if it
|
||||||
|
applies in this language. How readable is it?
|
||||||
|
|
||||||
|
Then please share your thoughts in a comment on the submission. Did this
|
||||||
|
experiment make the code better? Worse? Did you learn anything from it?
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @EduardoBautista
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @andrewclarkson
|
||||||
|
- @ashleygwilliams
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @EduardoBautista
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @IanWhitney
|
||||||
|
- @kytrinyx
|
||||||
|
- @leoyvens
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @murlakatamenka
|
||||||
|
- @navossoc
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @pminten
|
||||||
|
- @razielgn
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Learn to Program by Chris Pine - http://pine.fm/LearnToProgram/?Chapter=06
|
7
beer-song/src/lib.rs
Normal file
7
beer-song/src/lib.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
pub fn verse(n: u32) -> String {
|
||||||
|
unimplemented!("emit verse {}", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sing(start: u32, end: u32) -> String {
|
||||||
|
unimplemented!("sing verses {} to {}, inclusive", start, end)
|
||||||
|
}
|
36
beer-song/tests/beer-song.rs
Normal file
36
beer-song/tests/beer-song.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
use beer_song as beer;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_verse_0() {
|
||||||
|
assert_eq!(beer::verse(0), "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_verse_1() {
|
||||||
|
assert_eq!(beer::verse(1), "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_verse_2() {
|
||||||
|
assert_eq!(beer::verse(2), "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_verse_8() {
|
||||||
|
assert_eq!(beer::verse(8), "8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_song_8_6() {
|
||||||
|
assert_eq!(beer::sing(8, 6), "8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n\n7 bottles of beer on the wall, 7 bottles of beer.\nTake one down and pass it around, 6 bottles of beer on the wall.\n\n6 bottles of beer on the wall, 6 bottles of beer.\nTake one down and pass it around, 5 bottles of beer on the wall.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn test_song_3_0() {
|
||||||
|
assert_eq!(beer::sing(3, 0), "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n\n2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n");
|
||||||
|
}
|
33
binary-search/.exercism/config.json
Normal file
33
binary-search/.exercism/config.json
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"blurb": "Implement a binary search algorithm.",
|
||||||
|
"authors": [
|
||||||
|
"shybyte"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"Cohen-Carlisle",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"lutostag",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/binary-search.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Wikipedia",
|
||||||
|
"source_url": "http://en.wikipedia.org/wiki/Binary_search_algorithm"
|
||||||
|
}
|
1
binary-search/.exercism/metadata.json
Normal file
1
binary-search/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"binary-search","id":"15b88c72f04946879f100f8c7de68577","url":"https://exercism.org/tracks/rust/exercises/binary-search","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
binary-search/.gitignore
vendored
Normal file
8
binary-search/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
9
binary-search/Cargo.toml
Normal file
9
binary-search/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "binary-search"
|
||||||
|
version = "1.3.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
generic = []
|
85
binary-search/HELP.md
Normal file
85
binary-search/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
109
binary-search/README.md
Normal file
109
binary-search/README.md
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
# Binary Search
|
||||||
|
|
||||||
|
Welcome to Binary Search on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Implement a binary search algorithm.
|
||||||
|
|
||||||
|
Searching a sorted collection is a common task. A dictionary is a sorted
|
||||||
|
list of word definitions. Given a word, one can find its definition. A
|
||||||
|
telephone book is a sorted list of people's names, addresses, and
|
||||||
|
telephone numbers. Knowing someone's name allows one to quickly find
|
||||||
|
their telephone number and address.
|
||||||
|
|
||||||
|
If the list to be searched contains more than a few items (a dozen, say)
|
||||||
|
a binary search will require far fewer comparisons than a linear search,
|
||||||
|
but it imposes the requirement that the list be sorted.
|
||||||
|
|
||||||
|
In computer science, a binary search or half-interval search algorithm
|
||||||
|
finds the position of a specified input value (the search "key") within
|
||||||
|
an array sorted by key value.
|
||||||
|
|
||||||
|
In each step, the algorithm compares the search key value with the key
|
||||||
|
value of the middle element of the array.
|
||||||
|
|
||||||
|
If the keys match, then a matching element has been found and its index,
|
||||||
|
or position, is returned.
|
||||||
|
|
||||||
|
Otherwise, if the search key is less than the middle element's key, then
|
||||||
|
the algorithm repeats its action on the sub-array to the left of the
|
||||||
|
middle element or, if the search key is greater, on the sub-array to the
|
||||||
|
right.
|
||||||
|
|
||||||
|
If the remaining array to be searched is empty, then the key cannot be
|
||||||
|
found in the array and a special "not found" indication is returned.
|
||||||
|
|
||||||
|
A binary search halves the number of items to check with each iteration,
|
||||||
|
so locating an item (or determining its absence) takes logarithmic time.
|
||||||
|
A binary search is a dichotomic divide and conquer search algorithm.
|
||||||
|
|
||||||
|
## Restrictions
|
||||||
|
|
||||||
|
Rust provides in its standard library already a
|
||||||
|
[binary search function](https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search).
|
||||||
|
For this exercise you should not use this function but just other basic tools instead.
|
||||||
|
|
||||||
|
## Hints
|
||||||
|
|
||||||
|
[Slices](https://doc.rust-lang.org/book/2018-edition/ch04-03-slices.html) have additionally to
|
||||||
|
the normal element access via indexing (slice[index]) many useful functions like
|
||||||
|
[split_at](https://doc.rust-lang.org/std/primitive.slice.html#method.split_at) or [getting
|
||||||
|
subslices](https://doc.rust-lang.org/std/primitive.slice.html#method.get) (slice[start..end]).
|
||||||
|
|
||||||
|
You can solve this exercise by just using boring old element access via indexing, but maybe the
|
||||||
|
other provided functions can make your code cleaner and safer.
|
||||||
|
|
||||||
|
## For bonus points
|
||||||
|
|
||||||
|
Did you get the tests passing and the code clean? If you want to, there
|
||||||
|
are some additional things you could try.
|
||||||
|
|
||||||
|
- Currently your find function will probably only work for slices of numbers,
|
||||||
|
but the Rust type system is flexible enough to create a find function which
|
||||||
|
works on all slices which contains elements which can be ordered.
|
||||||
|
- Additionally this find function can work not only on slices, but at the
|
||||||
|
same time also on a Vec or an Array.
|
||||||
|
|
||||||
|
To run the bonus tests, remove the `#[ignore]` flag and execute the tests with
|
||||||
|
the `generic` feature, like this:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test --features generic
|
||||||
|
```
|
||||||
|
|
||||||
|
Then please share your thoughts in a comment on the submission. Did this
|
||||||
|
experiment make the code better? Worse? Did you learn anything from it?
|
||||||
|
|
||||||
|
### Hints for Bonus Points
|
||||||
|
|
||||||
|
- To get your function working with all kind of elements which can be ordered,
|
||||||
|
have a look at the [Ord Trait](https://doc.rust-lang.org/std/cmp/trait.Ord.html).
|
||||||
|
- To get your function working directly on Vec and Array, you can use the
|
||||||
|
[AsRef Trait](https://doc.rust-lang.org/std/convert/trait.AsRef.html)
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @shybyte
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @Cohen-Carlisle
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @lutostag
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @rofrol
|
||||||
|
- @stringparser
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Wikipedia - http://en.wikipedia.org/wiki/Binary_search_algorithm
|
7
binary-search/src/lib.rs
Normal file
7
binary-search/src/lib.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
pub fn find(array: &[i32], key: i32) -> Option<usize> {
|
||||||
|
unimplemented!(
|
||||||
|
"Using the binary search algorithm, find the element '{}' in the array '{:?}' and return its index.",
|
||||||
|
key,
|
||||||
|
array
|
||||||
|
);
|
||||||
|
}
|
108
binary-search/tests/binary-search.rs
Normal file
108
binary-search/tests/binary-search.rs
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
use binary_search::find;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn finds_a_value_in_an_array_with_one_element() {
|
||||||
|
assert_eq!(find(&[6], 6), Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_first_value_in_an_array_with_two_element() {
|
||||||
|
assert_eq!(find(&[1, 2], 1), Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_second_value_in_an_array_with_two_element() {
|
||||||
|
assert_eq!(find(&[1, 2], 2), Some(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_a_value_in_the_middle_of_an_array() {
|
||||||
|
assert_eq!(find(&[1, 3, 4, 6, 8, 9, 11], 6), Some(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_a_value_at_the_beginning_of_an_array() {
|
||||||
|
assert_eq!(find(&[1, 3, 4, 6, 8, 9, 11], 1), Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_a_value_at_the_end_of_an_array() {
|
||||||
|
assert_eq!(find(&[1, 3, 4, 6, 8, 9, 11], 11), Some(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_a_value_in_an_array_of_odd_length() {
|
||||||
|
assert_eq!(
|
||||||
|
find(&[1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], 144),
|
||||||
|
Some(9)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn finds_a_value_in_an_array_of_even_length() {
|
||||||
|
assert_eq!(
|
||||||
|
find(&[1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21),
|
||||||
|
Some(5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn identifies_that_a_value_is_not_included_in_the_array() {
|
||||||
|
assert_eq!(find(&[1, 3, 4, 6, 8, 9, 11], 7), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn a_value_smaller_than_the_arrays_smallest_value_is_not_included() {
|
||||||
|
assert_eq!(find(&[1, 3, 4, 6, 8, 9, 11], 0), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn a_value_larger_than_the_arrays_largest_value_is_not_included() {
|
||||||
|
assert_eq!(find(&[1, 3, 4, 6, 8, 9, 11], 13), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn nothing_is_included_in_an_empty_array() {
|
||||||
|
assert_eq!(find(&[], 1), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn nothing_is_found_when_the_left_and_right_bounds_cross() {
|
||||||
|
assert_eq!(find(&[1, 2], 0), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
#[cfg(feature = "generic")]
|
||||||
|
fn works_for_arrays() {
|
||||||
|
assert_eq!(find([6], 6), Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
#[cfg(feature = "generic")]
|
||||||
|
fn works_for_vec() {
|
||||||
|
let vector = vec![6];
|
||||||
|
assert_eq!(find(&vector, 6), Some(0));
|
||||||
|
assert_eq!(find(vector, 6), Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
#[cfg(feature = "generic")]
|
||||||
|
fn works_for_str_elements() {
|
||||||
|
assert_eq!(find(["a"], "a"), Some(0));
|
||||||
|
assert_eq!(find(["a", "b"], "b"), Some(1));
|
||||||
|
}
|
49
bob/.exercism/config.json
Normal file
49
bob/.exercism/config.json
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
{
|
||||||
|
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
|
||||||
|
"authors": [
|
||||||
|
"EduardoBautista"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"andrewclarkson",
|
||||||
|
"ashleygwilliams",
|
||||||
|
"austinlyons",
|
||||||
|
"cjmochrie",
|
||||||
|
"cmccandless",
|
||||||
|
"coriolinus",
|
||||||
|
"cwhakes",
|
||||||
|
"EduardoBautista",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"etrepum",
|
||||||
|
"f3rn0s",
|
||||||
|
"IanWhitney",
|
||||||
|
"kytrinyx",
|
||||||
|
"leoyvens",
|
||||||
|
"lewisclement",
|
||||||
|
"lutostag",
|
||||||
|
"mkantor",
|
||||||
|
"nfiles",
|
||||||
|
"petertseng",
|
||||||
|
"pminten",
|
||||||
|
"rofrol",
|
||||||
|
"rpottsoh",
|
||||||
|
"stefanv",
|
||||||
|
"stringparser",
|
||||||
|
"vvv",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/bob.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.",
|
||||||
|
"source_url": "http://pine.fm/LearnToProgram/?Chapter=06"
|
||||||
|
}
|
1
bob/.exercism/metadata.json
Normal file
1
bob/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"bob","id":"0f1553f8edca4c5da521e13ac141a2be","url":"https://exercism.org/tracks/rust/exercises/bob","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
bob/.gitignore
vendored
Normal file
8
bob/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
4
bob/Cargo.toml
Normal file
4
bob/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "bob"
|
||||||
|
version = "1.6.0"
|
85
bob/HELP.md
Normal file
85
bob/HELP.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
All but the first test have been ignored. After you get the first test to
|
||||||
|
pass, open the tests source file which is located in the `tests` directory
|
||||||
|
and remove the `#[ignore]` flag from the next test and get the tests to pass
|
||||||
|
again. Each separate test is a function with `#[test]` flag above it.
|
||||||
|
Continue, until you pass every test.
|
||||||
|
|
||||||
|
If you wish to run _only ignored_ tests without editing the tests source file, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rust 1.51 or later, you can run _all_ tests with
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test -- --include-ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To run a specific test, for example `some_test`, you can use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test
|
||||||
|
```
|
||||||
|
|
||||||
|
If the specific test is ignored, use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo test some_test -- --ignored
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn more about Rust tests refer to the online [test documentation][rust-tests].
|
||||||
|
|
||||||
|
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
## Rust Installation
|
||||||
|
|
||||||
|
Refer to the [exercism help page][help-page] for Rust installation and learning
|
||||||
|
resources.
|
||||||
|
|
||||||
|
## Submitting the solution
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Feedback, Issues, Pull Requests
|
||||||
|
|
||||||
|
The GitHub [track repository][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!
|
||||||
|
|
||||||
|
If you want to know more about Exercism, take a look at the [contribution guide].
|
||||||
|
|
||||||
|
## Submitting Incomplete Solutions
|
||||||
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||||
|
|
||||||
|
[help-page]: https://exercism.org/tracks/rust/learning
|
||||||
|
[github]: https://github.com/exercism/rust
|
||||||
|
[contribution guide]: https://exercism.org/docs/community/contributors
|
62
bob/README.md
Normal file
62
bob/README.md
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
# Bob
|
||||||
|
|
||||||
|
Welcome to Bob on Exercism's Rust Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
|
||||||
|
|
||||||
|
Bob answers 'Sure.' if you ask him a question, such as "How are you?".
|
||||||
|
|
||||||
|
He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
|
||||||
|
|
||||||
|
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
|
||||||
|
|
||||||
|
He says 'Fine. Be that way!' if you address him without actually saying
|
||||||
|
anything.
|
||||||
|
|
||||||
|
He answers 'Whatever.' to anything else.
|
||||||
|
|
||||||
|
Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @EduardoBautista
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @andrewclarkson
|
||||||
|
- @ashleygwilliams
|
||||||
|
- @austinlyons
|
||||||
|
- @cjmochrie
|
||||||
|
- @cmccandless
|
||||||
|
- @coriolinus
|
||||||
|
- @cwhakes
|
||||||
|
- @EduardoBautista
|
||||||
|
- @efx
|
||||||
|
- @ErikSchierboom
|
||||||
|
- @etrepum
|
||||||
|
- @f3rn0s
|
||||||
|
- @IanWhitney
|
||||||
|
- @kytrinyx
|
||||||
|
- @leoyvens
|
||||||
|
- @lewisclement
|
||||||
|
- @lutostag
|
||||||
|
- @mkantor
|
||||||
|
- @nfiles
|
||||||
|
- @petertseng
|
||||||
|
- @pminten
|
||||||
|
- @rofrol
|
||||||
|
- @rpottsoh
|
||||||
|
- @stefanv
|
||||||
|
- @stringparser
|
||||||
|
- @vvv
|
||||||
|
- @xakon
|
||||||
|
- @ZapAnton
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06
|
3
bob/src/lib.rs
Normal file
3
bob/src/lib.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn reply(message: &str) -> &str {
|
||||||
|
unimplemented!("have Bob reply to the incoming message: {}", message)
|
||||||
|
}
|
190
bob/tests/bob.rs
Normal file
190
bob/tests/bob.rs
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
fn process_response_case(phrase: &str, expected_response: &str) {
|
||||||
|
assert_eq!(bob::reply(phrase), expected_response);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
/// stating something
|
||||||
|
fn test_stating_something() {
|
||||||
|
process_response_case("Tom-ay-to, tom-aaaah-to.", "Whatever.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// ending with whitespace
|
||||||
|
fn test_ending_with_whitespace() {
|
||||||
|
process_response_case("Okay if like my spacebar quite a bit? ", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// shouting numbers
|
||||||
|
fn test_shouting_numbers() {
|
||||||
|
process_response_case("1, 2, 3 GO!", "Whoa, chill out!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// other whitespace
|
||||||
|
fn test_other_whitespace() {
|
||||||
|
process_response_case("\r\r ", "Fine. Be that way!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// shouting with special characters
|
||||||
|
fn test_shouting_with_special_characters() {
|
||||||
|
process_response_case(
|
||||||
|
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
|
||||||
|
"Whoa, chill out!",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// talking forcefully
|
||||||
|
fn test_talking_forcefully() {
|
||||||
|
process_response_case("Hi there!", "Whatever.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// prattling on
|
||||||
|
fn test_prattling_on() {
|
||||||
|
process_response_case("Wait! Hang on. Are you going to be OK?", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// forceful question
|
||||||
|
fn test_forceful_question() {
|
||||||
|
process_response_case("WHAT'S GOING ON?", "Calm down, I know what I'm doing!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// shouting with no exclamation mark
|
||||||
|
fn test_shouting_with_no_exclamation_mark() {
|
||||||
|
process_response_case("I HATE THE DENTIST", "Whoa, chill out!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// asking gibberish
|
||||||
|
fn test_asking_gibberish() {
|
||||||
|
process_response_case("fffbbcbeab?", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// question with no letters
|
||||||
|
fn test_question_with_no_letters() {
|
||||||
|
process_response_case("4?", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// no letters
|
||||||
|
fn test_no_letters() {
|
||||||
|
process_response_case("1, 2, 3", "Whatever.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// statement containing question mark
|
||||||
|
fn test_statement_containing_question_mark() {
|
||||||
|
process_response_case("Ending with ? means a question.", "Whatever.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//NEW
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// multiple line question
|
||||||
|
fn test_multiple_line_question() {
|
||||||
|
process_response_case(
|
||||||
|
"\rDoes this cryogenic chamber make me look fat?\rNo.",
|
||||||
|
"Whatever.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// non-question ending with whitespace
|
||||||
|
fn test_nonquestion_ending_with_whitespace() {
|
||||||
|
process_response_case(
|
||||||
|
"This is a statement ending with whitespace ",
|
||||||
|
"Whatever.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// shouting
|
||||||
|
fn test_shouting() {
|
||||||
|
process_response_case("WATCH OUT!", "Whoa, chill out!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// non-letters with question
|
||||||
|
fn test_nonletters_with_question() {
|
||||||
|
process_response_case(":) ?", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// shouting gibberish
|
||||||
|
fn test_shouting_gibberish() {
|
||||||
|
process_response_case("FCECDFCAAB", "Whoa, chill out!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// asking a question
|
||||||
|
fn test_asking_a_question() {
|
||||||
|
process_response_case("Does this cryogenic chamber make me look fat?", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// asking a numeric question
|
||||||
|
fn test_asking_a_numeric_question() {
|
||||||
|
process_response_case("You are, what, like 15?", "Sure.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// silence
|
||||||
|
fn test_silence() {
|
||||||
|
process_response_case("", "Fine. Be that way!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// starting with whitespace
|
||||||
|
fn test_starting_with_whitespace() {
|
||||||
|
process_response_case(" hmmmmmmm...", "Whatever.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// using acronyms in regular speech
|
||||||
|
fn test_using_acronyms_in_regular_speech() {
|
||||||
|
process_response_case(
|
||||||
|
"It's OK if you don't want to go work for NASA.",
|
||||||
|
"Whatever.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// alternate silence
|
||||||
|
fn test_alternate_silence() {
|
||||||
|
process_response_case(" ", "Fine. Be that way!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
/// prolonged silence
|
||||||
|
fn test_prolonged_silence() {
|
||||||
|
process_response_case(" ", "Fine. Be that way!");
|
||||||
|
}
|
31
book-store/.exercism/config.json
Normal file
31
book-store/.exercism/config.json
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
"blurb": "To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts of multiple-book purchases.",
|
||||||
|
"authors": [
|
||||||
|
"coriolinus"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"Baelyk",
|
||||||
|
"cwhakes",
|
||||||
|
"efx",
|
||||||
|
"ErikSchierboom",
|
||||||
|
"lutostag",
|
||||||
|
"petertseng",
|
||||||
|
"rofrol",
|
||||||
|
"stringparser",
|
||||||
|
"xakon",
|
||||||
|
"ZapAnton"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"src/lib.rs"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"tests/book-store.rs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.rs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Inspired by the harry potter kata from Cyber-Dojo.",
|
||||||
|
"source_url": "http://cyber-dojo.org"
|
||||||
|
}
|
1
book-store/.exercism/metadata.json
Normal file
1
book-store/.exercism/metadata.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"track":"rust","exercise":"book-store","id":"9df4cf2d792047ecab8162375b94b3c0","url":"https://exercism.org/tracks/rust/exercises/book-store","handle":"snowyforest","is_requester":true,"auto_approve":false}
|
8
book-store/.gitignore
vendored
Normal file
8
book-store/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
|
||||||
|
Cargo.lock
|
6
book-store/Cargo.toml
Normal file
6
book-store/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
edition = "2021"
|
||||||
|
name = "book_store"
|
||||||
|
version = "1.3.0"
|
||||||
|
|
||||||
|
[dependencies]
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue