Skip to content

Commit

Permalink
Sync scrabble score (exercism#680)
Browse files Browse the repository at this point in the history
[no important files changed]
  • Loading branch information
mk-mxp authored and tomasnorre committed May 7, 2024
1 parent 6dd3dc0 commit d5ec646
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 87 deletions.
47 changes: 16 additions & 31 deletions exercises/practice/scrabble-score/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
# Instructions

Given a word, compute the Scrabble score for that word.
Your task is to compute a word's Scrabble score by summing the values of its letters.

## Letter Values
The letters are valued as follows:

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 |

```text
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:
For example, the word "cabbage" is worth 14 points:

- 3 points for C
- 1 point for A, twice
- 3 points for B, twice
- 1 point for A
- 3 points for B
- 3 points for B
- 1 point for A
- 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.
7 changes: 7 additions & 0 deletions exercises/practice/scrabble-score/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Introduction

[Scrabble][wikipedia] is a word game where players place letter tiles on a board to form words.
Each letter has a value.
A word's score is the sum of its letters' values.

[wikipedia]: https://en.wikipedia.org/wiki/Scrabble
3 changes: 2 additions & 1 deletion exercises/practice/scrabble-score/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"arueckauer",
"kunicmarko20",
"kytrinyx",
"petemcfarlane"
"petemcfarlane",
"mk-mxp"
],
"files": {
"solution": [
Expand Down
22 changes: 0 additions & 22 deletions exercises/practice/scrabble-score/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function score($word)
Expand Down
55 changes: 22 additions & 33 deletions exercises/practice/scrabble-score/ScrabbleScoreTest.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

/**
Expand All @@ -35,7 +13,8 @@ public static function setUpBeforeClass(): void
}

/**
* Test lowercase single letter word.
* uuid f46cda29-1ca5-4ef2-bd45-388a767e3db2
* @testdox Lowercase letter
*/
public function testLowercaseSingleLetter(): void
{
Expand All @@ -44,7 +23,8 @@ public function testLowercaseSingleLetter(): void
}

/**
* Test uppercase single letter word.
* uuid f7794b49-f13e-45d1-a933-4e48459b2201
* @testdox Uppercase letter
*/
public function testUppercaseSingleLetter(): void
{
Expand All @@ -53,7 +33,8 @@ public function testUppercaseSingleLetter(): void
}

/**
* Test valuable single letter word.
* uuid eaba9c76-f9fa-49c9-a1b0-d1ba3a5b31fa
* @testdox Valuable letter
*/
public function testValuableSingleLetter(): void
{
Expand All @@ -62,7 +43,8 @@ public function testValuableSingleLetter(): void
}

/**
* Test short word.
* uuid f3c8c94e-bb48-4da2-b09f-e832e103151e
* @testdox Short word
*/
public function testShortWord(): void
{
Expand All @@ -71,7 +53,8 @@ public function testShortWord(): void
}

/**
* Test short valuable word.
* uuid 71e3d8fa-900d-4548-930e-68e7067c4615
* @testdox Short, valuable word
*/
public function testShortValuableWord(): void
{
Expand All @@ -80,7 +63,8 @@ public function testShortValuableWord(): void
}

/**
* Test medium word.
* uuid d3088ad9-570c-4b51-8764-c75d5a430e99
* @testdox Medium word
*/
public function testMediumWord(): void
{
Expand All @@ -89,7 +73,8 @@ public function testMediumWord(): void
}

/**
* Test medium valuable word.
* uuid fa20c572-ad86-400a-8511-64512daac352
* @testdox Medium, valuable word
*/
public function testMediumValuableWord(): void
{
Expand All @@ -98,7 +83,8 @@ public function testMediumValuableWord(): void
}

/**
* Test long mixed-case word.
* uuid 9336f0ba-9c2b-4fa0-bd1c-2e2d328cf967
* @testdox Long, mixed-case word
*/
public function testLongMixedCaseWord(): void
{
Expand All @@ -107,7 +93,8 @@ public function testLongMixedCaseWord(): void
}

/**
* Test english-like word.
* uuid 1e34e2c3-e444-4ea7-b598-3c2b46fd2c10
* @testdox English-like word
*/
public function testEnglishLikeWord(): void
{
Expand All @@ -116,7 +103,8 @@ public function testEnglishLikeWord(): void
}

/**
* Test empty word score.
* uuid 4efe3169-b3b6-4334-8bae-ff4ef24a7e4f
* @testdox Empty input
*/
public function testEmptyWordScore(): void
{
Expand All @@ -125,7 +113,8 @@ public function testEmptyWordScore(): void
}

/*
* Test entire alphabet word.
* uuid 3b305c1c-f260-4e15-a5b5-cb7d3ea7c3d7
* @testdox Entire alphabet available
*/
public function testEntireAlphabetWord(): void
{
Expand Down

0 comments on commit d5ec646

Please sign in to comment.