Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust scrabble score #250

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
- [allergies](./allergies/README.md)
- [difference-of-squares](./difference-of-squares/README.md)
- [anagram](./anagram/README.md)
- [scrabble-score](./scrabble-score/README.md)
40 changes: 40 additions & 0 deletions rust/scrabble-score/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"authors": [
"IanWhitney"
],
"contributors": [
"ashleygwilliams",
"AvasDream",
"coriolinus",
"cwhakes",
"efx",
"ErikSchierboom",
"IanWhitney",
"juleskers",
"kotp",
"lutostag",
"mkantor",
"navossoc",
"nfiles",
"petertseng",
"rofrol",
"stringparser",
"xakon",
"ZapAnton"
],
"files": {
"solution": [
"src/lib.rs",
"Cargo.toml"
],
"test": [
"tests/scrabble-score.rs"
],
"example": [
".meta/example.rs"
]
},
"blurb": "Given a word, compute the Scrabble score for that word.",
"source": "Inspired by the Extreme Startup game",
"source_url": "https://github.com/rchatley/extreme_startup"
}
1 change: 1 addition & 0 deletions rust/scrabble-score/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"rust","exercise":"scrabble-score","id":"4cf847a06ce14af8a0e1f6061e332429","url":"https://exercism.org/tracks/rust/exercises/scrabble-score","handle":"vpayno","is_requester":true,"auto_approve":false}
8 changes: 8 additions & 0 deletions rust/scrabble-score/.gitignore
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions rust/scrabble-score/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
edition = "2021"
name = "scrabble-score"
version = "1.1.0"
86 changes: 86 additions & 0 deletions rust/scrabble-score/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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)
- The [Rust track's programming category on the forum](https://forum.exercism.org/c/programming/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
81 changes: 81 additions & 0 deletions rust/scrabble-score/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Scrabble Score

Welcome to Scrabble Score on Exercism's Rust Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Instructions

Given a word, compute the Scrabble score for that word.

## Letter Values

You'll need these:

```text
Letter Value
A, E, I, O, U, L, N, R, S, T 1
D, G 2
B, C, M, P 3
F, H, V, W, Y 4
K 5
J, X 8
Q, Z 10
```

## Examples

"cabbage" should be scored as worth 14 points:

- 3 points for C
- 1 point for A, twice
- 3 points for B, twice
- 2 points for G
- 1 point for E

And to total:

- `3 + 2*1 + 2*3 + 2 + 1`
- = `3 + 2 + 6 + 3`
- = `5 + 9`
- = 14

## Extensions

- You can play a double or a triple letter.
- You can play a double or a triple word.

## Source

### Created by

- @IanWhitney

### Contributed to by

- @ashleygwilliams
- @AvasDream
- @coriolinus
- @cwhakes
- @efx
- @ErikSchierboom
- @IanWhitney
- @juleskers
- @kotp
- @lutostag
- @mkantor
- @navossoc
- @nfiles
- @petertseng
- @rofrol
- @stringparser
- @xakon
- @ZapAnton

### Based on

Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup

### My Solution

- [my solution](./src/lib.rs)
- [run-tests](./run-tests-rust.txt)
64 changes: 64 additions & 0 deletions rust/scrabble-score/coverage-annotations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
1| |/// Compute the Scrabble score for a word.
2| |
3| |/// Scores a scrabble word.
4| |///
5| |/// ```rust
6| |/// use scrabble_score::*;
7| |///
8| |/// let want: u64 = 87;
9| |/// let got: u64 = score("abcdefghijklmnopqrstuvwxyz");
10| |///
11| |/// assert_eq!(got, want);
12| |/// ```
13| 42|pub fn score(word: &str) -> u64 {
14| 42| word.to_lowercase()
15| 42| .trim()
16| 42| .chars()
17| 258| .map(|c| match c {
18| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1,
19| 6| 'd' | 'g' => 2,
20| 24| 'b' | 'c' | 'm' | 'p' => 3,
21| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4,
22| 6| 'k' => 5,
23| 9| 'j' | 'x' => 8,
24| 15| 'q' | 'z' => 10,
25| 6| _ => 0,
26| 258| })
------------------
| scrabble_score::score::{closure#0}:
| 17| 258| .map(|c| match c {
| 18| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1,
| 19| 6| 'd' | 'g' => 2,
| 20| 24| 'b' | 'c' | 'm' | 'p' => 3,
| 21| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4,
| 22| 6| 'k' => 5,
| 23| 9| 'j' | 'x' => 8,
| 24| 15| 'q' | 'z' => 10,
| 25| 6| _ => 0,
| 26| 258| })
------------------
| Unexecuted instantiation: scrabble_score::score::{closure#0}
------------------
27| 42| .sum()
28| 42|}
------------------
| scrabble_score::score:
| 13| 42|pub fn score(word: &str) -> u64 {
| 14| 42| word.to_lowercase()
| 15| 42| .trim()
| 16| 42| .chars()
| 17| 42| .map(|c| match c {
| 18| | 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1,
| 19| | 'd' | 'g' => 2,
| 20| | 'b' | 'c' | 'm' | 'p' => 3,
| 21| | 'f' | 'h' | 'v' | 'w' | 'y' => 4,
| 22| | 'k' => 5,
| 23| | 'j' | 'x' => 8,
| 24| | 'q' | 'z' => 10,
| 25| | _ => 0,
| 26| 42| })
| 27| 42| .sum()
| 28| 42|}
------------------
| Unexecuted instantiation: scrabble_score::score
------------------
8 changes: 8 additions & 0 deletions rust/scrabble-score/coverage-missing-lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Running: cargo llvm-cov --no-clean --all-features --workspace --show-missing-lines

Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs 12 0 100.00% 2 0 100.00% 18 0 100.00% 0 0 -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 12 0 100.00% 2 0 100.00% 18 0 100.00% 0 0 -

32 changes: 32 additions & 0 deletions rust/scrabble-score/report.lcov
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SF:/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs
FN:17,_RNCNvCsbE52QhvtJFr_14scrabble_score5score0B3_
FN:13,_RNvCsbE52QhvtJFr_14scrabble_score5score
FN:17,_RNCNvCsfA8C7faOhHu_14scrabble_score5score0B3_
FN:13,_RNvCsfA8C7faOhHu_14scrabble_score5score
FNDA:86,_RNCNvCsbE52QhvtJFr_14scrabble_score5score0B3_
FNDA:14,_RNvCsbE52QhvtJFr_14scrabble_score5score
FNDA:0,_RNCNvCsfA8C7faOhHu_14scrabble_score5score0B3_
FNDA:0,_RNvCsfA8C7faOhHu_14scrabble_score5score
FNF:2
FNH:2
DA:13,14
DA:14,14
DA:15,14
DA:16,14
DA:17,86
DA:18,55
DA:19,2
DA:20,8
DA:21,9
DA:22,2
DA:23,3
DA:24,5
DA:25,2
DA:26,86
DA:27,14
DA:28,14
BRF:0
BRH:0
LF:18
LH:18
end_of_record
Loading