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

Add Scrabble Score #125

Merged
merged 1 commit into from
May 25, 2016
Merged

Add Scrabble Score #125

merged 1 commit into from
May 25, 2016

Conversation

IanWhitney
Copy link
Contributor

@IanWhitney IanWhitney commented May 17, 2016

Implements the Scrabble Score exercise.

As of right now there is no official test suite for Scrabble Score. There is a PR (exercism/problem-specifications#161), but it is not yet merged.

I am following the test suite in that PR, with one exception. I thought it was likely that a common naive implementation would be to map through the chars, find the score and then simply unwrap the value. Like this:

word.chars().map(|c| values.get(&c).fold(0, |sum, v| sum + v.unwrap())

So I have added a test that uses a non-English character that will cause this implementation to panic.

I've put this exercise between the Nucleotides and Roman Numerals, figuring that it did similar character iteration and value mapping.

My example implementation probably leaves a lot to be desired. I wanted to make the values hash a static, but you can't do that with a hash.

Lazy Static does let you do this, but I'm not going to require a crate in my example.

@IanWhitney
Copy link
Contributor Author

I'm going to wait for exercism/problem-specifications#255 to merge before finishing this PR

@IanWhitney
Copy link
Contributor Author

Updated to follow exercism/problem-specifications#255

I'll wait a few days for comments. I'd like to merge this by May 24th, if there are no problems.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Implements the Scrabble Score exercise.

As of right now there is no official test suite for Scrabble Score.
There is a PR (exercism/problem-specifications#161), but it
is not yet merged.

I've put this exercise between the Nucleotides and Roman Numerals,
figuring that it did similar character iteration and value mapping.

I am following the test suite in that PR, with one exception. I thought
it was likely that a common naive implementation would be to map through
the chars, find the score and then simply unwrap the value. Like this

```
word.chars().map(|c| values.get(&c).fold(0, |sum, v| sum + v.unwrap())
```

So I have added a test that uses a non-English character that will cause this
implementation to panic.

My example implementation probably leaves a lot to be desired. I wanted
to make the values hash a static, but you can't do that with a hash.
([Lazy
Static](http://rust-lang-nursery.github.io/lazy-static.rs/lazy_static/index.html)
does let you do this, but I'm not going to require a crate in my
example).
@IanWhitney IanWhitney merged commit 83e4c0b into exercism:master May 25, 2016
@IanWhitney IanWhitney deleted the scrabble_score branch May 25, 2016 13:57
@petertseng
Copy link
Member

I dropped the ball.

But I don't see anything I would change.

Honestly I may have done the inserts with iterating over a Vector<(char, u16)> or something (avoids repeating insert so many times) but that's really not important enough to be really worth mentioning I guess

@IanWhitney
Copy link
Contributor Author

Now that I found https://doc.rust-lang.org/std/iter/trait.FromIterator.html, I'd probably use that in the example. But it doesn't really matter now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants