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

freddie2025's solution

to Scrabble Score in the C# Track

Published at Apr 08 2019 · 0 comments
Test suite


This exercise has changed since this solution 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


"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 the tests

To run the tests, run the command dotnet test from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the Skip property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using exercism submit ScrabbleScore.cs

Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.


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


// This file was auto-generated based on version 1.1.0 of the canonical data.

using Xunit;

public class ScrabbleScoreTest
    public void Lowercase_letter()
        Assert.Equal(1, ScrabbleScore.Score("a"));

    [Fact(Skip = "Remove to run test")]
    public void Uppercase_letter()
        Assert.Equal(1, ScrabbleScore.Score("A"));

    [Fact(Skip = "Remove to run test")]
    public void Valuable_letter()
        Assert.Equal(4, ScrabbleScore.Score("f"));

    [Fact(Skip = "Remove to run test")]
    public void Short_word()
        Assert.Equal(2, ScrabbleScore.Score("at"));

    [Fact(Skip = "Remove to run test")]
    public void Short_valuable_word()
        Assert.Equal(12, ScrabbleScore.Score("zoo"));

    [Fact(Skip = "Remove to run test")]
    public void Medium_word()
        Assert.Equal(6, ScrabbleScore.Score("street"));

    [Fact(Skip = "Remove to run test")]
    public void Medium_valuable_word()
        Assert.Equal(22, ScrabbleScore.Score("quirky"));

    [Fact(Skip = "Remove to run test")]
    public void Long_mixed_case_word()
        Assert.Equal(41, ScrabbleScore.Score("OxyphenButazone"));

    [Fact(Skip = "Remove to run test")]
    public void English_like_word()
        Assert.Equal(8, ScrabbleScore.Score("pinata"));

    [Fact(Skip = "Remove to run test")]
    public void Empty_input()
        Assert.Equal(0, ScrabbleScore.Score(""));

    [Fact(Skip = "Remove to run test")]
    public void Entire_alphabet_available()
        Assert.Equal(87, ScrabbleScore.Score("abcdefghijklmnopqrstuvwxyz"));
using System;
using System.Linq;
using System.Collections.Generic;

public static class ScrabbleScore
    private static Dictionary<char, int> LetterScores = new Dictionary<char, int>()
        {'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},
        {'J',8}, {'X',8},
        {'Q',10}, {'Z',10}

    public static int Score(string input)
        return input.ToUpper().Sum(x => LetterScores[x]);

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?