ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# thomchop's solution

## to Scrabble Score in the C# Track

Published at Oct 25 2020 · 0 comments
Instructions
Test suite
Solution

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

## Source

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

### ScrabbleScoreTests.cs

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

using Xunit;

public class ScrabbleScoreTests
{
[Fact]
public void Lowercase_letter()
{
Assert.Equal(1, ScrabbleScore.Score("a"));
}

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

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

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

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

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

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

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

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

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

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

public static class ScrabbleScore {
public static int Score(string input) {
int sum = 0;
char[] letters = input.ToLower().ToCharArray();
foreach (char letter in letters) {
sum += LetterValues[letter];
}
return sum;
}

private static Dictionary<char, int> LetterValues = 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},
{'k', 5},
{'j', 8},
{'x', 8},
{'q', 10},
{'z', 10},
};
}``````