# UnrelatedString's solution

## to Scrabble Score in the Erlang Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

#### Note:

This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

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

## Letter Values

You'll need these:

``````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.

## Running tests

In order to run the tests, issue the following command from the exercise directory:

For running the tests provided, `rebar3` is used as it is the official build and dependency management tool for erlang now. Please refer to the tracks installation instructions on how to do that.

In order to run the tests, you can issue the following command from the exercise directory.

``````\$ rebar3 eunit
``````

### Test versioning

Each problem defines a macro `TEST_VERSION` in the test file and verifies that the solution defines and exports a function `test_version` returning that same value.

``````-export([test_version/0]).

test_version() ->
1.
``````

The benefit of this is that reviewers can see against which test version an iteration was written if, for example, a previously posted solution does not solve the current problem or passes current tests.

## Questions?

For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.

## Source

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

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

### scrabble_score_tests.erl

``````-module(scrabble_score_tests).

-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(checkScore(N, S), ?assertEqual(N, scrabble_score:score(S))).

empty_word_scores_zero_test() -> ?checkScore(0, "").

scores_very_short_word_test() -> ?checkScore(1, "a").

scores_other_very_short_word_test() -> ?checkScore(4, "f").

simple_word_scores_the_number_of_letters_test() -> ?checkScore(6, "street").

complicated_word_scores_more_test() -> ?checkScore(22, "quirky").

scores_are_case_insensitive_test() ->
?checkScore(41, "oxyphenbutazone"),
?checkScore(41, "OXYPHENBUTAZONE").

version_test() ->
?assertMatch(1, scrabble_score:test_version()).``````
``````-module(scrabble_score).

-export([score/1, test_version/0]).

lscore(L) when L >= \$a ->
lscore(L - 32);
lscore(L) ->
case L of
\$A -> 1;
\$E -> 1;
\$I -> 1;
\$O -> 1;
\$U -> 1;
\$L -> 1;
\$N -> 1;
\$R -> 1;
\$S -> 1;
\$T -> 1;
\$D -> 2;
\$G -> 2;
\$B -> 3;
\$C -> 3;
\$M -> 3;
\$P -> 3;
\$F -> 4;
\$H -> 4;
\$V -> 4;
\$W -> 4;
\$Y -> 4;
\$K -> 5;
\$J -> 8;
\$X -> 8;
\$Q -> 10;
\$Z -> 10
end.

score([]) -> 0;
score([L | W]) ->
lscore(L) + score(W).

test_version() -> 1.``````

### What can you learn from this solution?

A huge amount can be learned from reading other peopleโs code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

• What compromises have been made?