🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of ikarachristos

ikarachristos's solution

to Scrabble Score in the Erlang Track

Published at Feb 02 2021 · 0 comments
Test suite

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


"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


  • 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


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.


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.


%% Generated with 'testgen v0.2.0'
%% Revision 1 of the exercises generator was used
%% https://github.com/exercism/problem-specifications/raw/42dd0cea20498fd544b152c4e2c0a419bb7e266a/exercises/scrabble-score/canonical-data.json
%% This file is automatically generated from the exercises canonical data.



'1_lowercase_letter_test_'() ->
    {"lowercase letter",
     ?_assertEqual(1, scrabble_score:score("a"))}.

'2_uppercase_letter_test_'() ->
    {"uppercase letter",
     ?_assertEqual(1, scrabble_score:score("A"))}.

'3_valuable_letter_test_'() ->
    {"valuable letter",
     ?_assertEqual(4, scrabble_score:score("f"))}.

'4_short_word_test_'() ->
    {"short word",
     ?_assertEqual(2, scrabble_score:score("at"))}.

'5_short_valuable_word_test_'() ->
    {"short, valuable word",
     ?_assertEqual(12, scrabble_score:score("zoo"))}.

'6_medium_word_test_'() ->
    {"medium word",
     ?_assertEqual(6, scrabble_score:score("street"))}.

'7_medium_valuable_word_test_'() ->
    {"medium, valuable word",
     ?_assertEqual(22, scrabble_score:score("quirky"))}.

'8_long_mixed_case_word_test_'() ->
    {"long, mixed-case word",

'9_english_like_word_test_'() ->
    {"english-like word",
     ?_assertEqual(8, scrabble_score:score("pinata"))}.

'10_empty_input_test_'() ->
    {"empty input",
     ?_assertEqual(0, scrabble_score:score([]))}.

'11_entire_alphabet_available_test_'() ->
    {"entire alphabet available",


score(Word) ->
  lists:foldl(fun(L, Sum) -> Sum + letter_score(L) end, 0, string:uppercase(Word)).

letter_score($D) -> 2;
letter_score($G) -> 2;
letter_score($B) -> 3;
letter_score($C) -> 3;
letter_score($M) -> 3;
letter_score($P) -> 3;
letter_score($F) -> 4;
letter_score($H) -> 4;
letter_score($V) -> 4;
letter_score($W) -> 4;
letter_score($Y) -> 4;
letter_score($K) -> 5;
letter_score($J) -> 8;
letter_score($X) -> 8;
letter_score($Q) -> 10;
letter_score($Z) -> 10;
letter_score(_L) -> 1.

Community comments

Find this solution interesting? Ask the author a question to learn more.

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?
  • Are there new concepts here that you could read more about to improve your understanding?