Skip to content

Commit 3b09787

Browse files
authored
scrabble-score-exercise: Added new exercise (#128)
1 parent 4a16e10 commit 3b09787

File tree

10 files changed

+233
-0
lines changed

10 files changed

+233
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@
390390
"practices": [],
391391
"prerequisites": [],
392392
"difficulty": 4
393+
},
394+
{
395+
"slug": "scrabble-score",
396+
"name": "Scrabble Score",
397+
"uuid": "b03f5c6e-86c4-4aa7-92cc-7587dd5dc3d3",
398+
"practices": [],
399+
"prerequisites": [],
400+
"difficulty": 4
393401
}
394402
]
395403
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Instructions
2+
3+
Your task is to compute a word's Scrabble score by summing the values of its letters.
4+
5+
The letters are valued as follows:
6+
7+
| Letter | Value |
8+
| ---------------------------- | ----- |
9+
| A, E, I, O, U, L, N, R, S, T | 1 |
10+
| D, G | 2 |
11+
| B, C, M, P | 3 |
12+
| F, H, V, W, Y | 4 |
13+
| K | 5 |
14+
| J, X | 8 |
15+
| Q, Z | 10 |
16+
17+
For example, the word "cabbage" is worth 14 points:
18+
19+
- 3 points for C
20+
- 1 point for A
21+
- 3 points for B
22+
- 3 points for B
23+
- 1 point for A
24+
- 2 points for G
25+
- 1 point for E
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
[Scrabble][wikipedia] is a word game where players place letter tiles on a board to form words.
4+
Each letter has a value.
5+
A word's score is the sum of its letters' values.
6+
7+
[wikipedia]: https://en.wikipedia.org/wiki/Scrabble
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"SimaDovakin"
4+
],
5+
"files": {
6+
"solution": [
7+
"scrabbleScore.u"
8+
],
9+
"test": [
10+
"scrabbleScore.test.u"
11+
],
12+
"example": [
13+
".meta/examples/scrabbleScore.example.u"
14+
]
15+
},
16+
"blurb": "Given a word, compute the Scrabble score for that word.",
17+
"source": "Inspired by the Extreme Startup game",
18+
"source_url": "https://github.com/rchatley/extreme_startup"
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
scrabbleScore.score : Text -> Nat
2+
scrabbleScore.score word =
3+
word
4+
|> toCharList
5+
|> List.foldLeft (total ch -> total + charToScore ch) 0
6+
7+
scrabbleScore.charToScore : Char -> Nat
8+
scrabbleScore.charToScore char =
9+
match toUppercase char with
10+
c | List.contains c [?A, ?E, ?I, ?O, ?U, ?L, ?N, ?R, ?S, ?T] -> 1
11+
c | List.contains c [?D, ?G] -> 2
12+
c | List.contains c [?B, ?C, ?M, ?P] -> 3
13+
c | List.contains c [?F, ?H, ?V, ?W, ?Y] -> 4
14+
c | List.contains c [?J, ?X] -> 8
15+
c | List.contains c [?Q, ?Z] -> 10
16+
?K -> 5
17+
_ -> 0
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"name": "scrabbleScore.score.tests.ex1",
4+
"test_code": "expect (1 == scrabbleScore.score \"a\")\n |> Test.label \"lowercase letter\""
5+
},
6+
{
7+
"name": "scrabbleScore.score.tests.ex2",
8+
"test_code": "expect (1 == scrabbleScore.score \"A\")\n |> Test.label \"uppercase letter\""
9+
},
10+
{
11+
"name": "scrabbleScore.score.tests.ex3",
12+
"test_code": "expect (4 == scrabbleScore.score \"f\")\n |> Test.label \"valuable letter\""
13+
},
14+
{
15+
"name": "scrabbleScore.score.tests.ex4",
16+
"test_code": "expect (2 == scrabbleScore.score \"at\")\n |> Test.label \"short word\""
17+
},
18+
{
19+
"name": "scrabbleScore.score.tests.ex5",
20+
"test_code": "expect (12 == scrabbleScore.score \"zoo\")\n |> Test.label \"short, valuable word\""
21+
},
22+
{
23+
"name": "scrabbleScore.score.tests.ex6",
24+
"test_code": "expect (6 == scrabbleScore.score \"street\")\n |> Test.label \"medium word\""
25+
},
26+
{
27+
"name": "scrabbleScore.score.tests.ex7",
28+
"test_code": "expect (22 == scrabbleScore.score \"quirky\")\n |> Test.label \"medium, valuable word\""
29+
},
30+
{
31+
"name": "scrabbleScore.score.tests.ex8",
32+
"test_code": "expect (41 == scrabbleScore.score \"OxyphenButazone\")\n |> Test.label \"long, mixed-case word\""
33+
},
34+
{
35+
"name": "scrabbleScore.score.tests.ex9",
36+
"test_code": "expect (8 == scrabbleScore.score \"pinata\")\n |> Test.label \"english-like word\""
37+
},
38+
{
39+
"name": "scrabbleScore.score.tests.ex10",
40+
"test_code": "expect (0 == scrabbleScore.score \"\")\n |> Test.label \"empty input\""
41+
},
42+
{
43+
"name": "scrabbleScore.score.tests.ex11",
44+
"test_code": "expect (87 == scrabbleScore.score \"abcdefghijklmnopqrstuvwxyz\")\n |> Test.label \"entire alphabet available\""
45+
}
46+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Testing transcript for scrabble-score exercise
2+
3+
```ucm
4+
.> load ./scrabbleScore.u
5+
.> add
6+
.> load ./scrabbleScore.test.u
7+
.> add
8+
.> move.term scrabbleScore.tests tests
9+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[f46cda29-1ca5-4ef2-bd45-388a767e3db2]
13+
description = "lowercase letter"
14+
15+
[f7794b49-f13e-45d1-a933-4e48459b2201]
16+
description = "uppercase letter"
17+
18+
[eaba9c76-f9fa-49c9-a1b0-d1ba3a5b31fa]
19+
description = "valuable letter"
20+
21+
[f3c8c94e-bb48-4da2-b09f-e832e103151e]
22+
description = "short word"
23+
24+
[71e3d8fa-900d-4548-930e-68e7067c4615]
25+
description = "short, valuable word"
26+
27+
[d3088ad9-570c-4b51-8764-c75d5a430e99]
28+
description = "medium word"
29+
30+
[fa20c572-ad86-400a-8511-64512daac352]
31+
description = "medium, valuable word"
32+
33+
[9336f0ba-9c2b-4fa0-bd1c-2e2d328cf967]
34+
description = "long, mixed-case word"
35+
36+
[1e34e2c3-e444-4ea7-b598-3c2b46fd2c10]
37+
description = "english-like word"
38+
39+
[4efe3169-b3b6-4334-8bae-ff4ef24a7e4f]
40+
description = "empty input"
41+
42+
[3b305c1c-f260-4e15-a5b5-cb7d3ea7c3d7]
43+
description = "entire alphabet available"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
scrabbleScore.score.tests.ex1 =
2+
expect (1 == scrabbleScore.score "a")
3+
|> Test.label "lowercase letter"
4+
5+
scrabbleScore.score.tests.ex2 =
6+
expect (1 == scrabbleScore.score "A")
7+
|> Test.label "uppercase letter"
8+
9+
scrabbleScore.score.tests.ex3 =
10+
expect (4 == scrabbleScore.score "f")
11+
|> Test.label "valuable letter"
12+
13+
scrabbleScore.score.tests.ex4 =
14+
expect (2 == scrabbleScore.score "at")
15+
|> Test.label "short word"
16+
17+
scrabbleScore.score.tests.ex5 =
18+
expect (12 == scrabbleScore.score "zoo")
19+
|> Test.label "short, valuable word"
20+
21+
scrabbleScore.score.tests.ex6 =
22+
expect (6 == scrabbleScore.score "street")
23+
|> Test.label "medium word"
24+
25+
scrabbleScore.score.tests.ex7 =
26+
expect (22 == scrabbleScore.score "quirky")
27+
|> Test.label "medium, valuable word"
28+
29+
scrabbleScore.score.tests.ex8 =
30+
expect (41 == scrabbleScore.score "OxyphenButazone")
31+
|> Test.label "long, mixed-case word"
32+
33+
scrabbleScore.score.tests.ex9 =
34+
expect (8 == scrabbleScore.score "pinata")
35+
|> Test.label "english-like word"
36+
37+
scrabbleScore.score.tests.ex10 =
38+
expect (0 == scrabbleScore.score "")
39+
|> Test.label "empty input"
40+
41+
scrabbleScore.score.tests.ex11 =
42+
expect (87 == scrabbleScore.score "abcdefghijklmnopqrstuvwxyz")
43+
|> Test.label "entire alphabet available"
44+
45+
test> scrabbleScore.tests = runAll [
46+
scrabbleScore.score.tests.ex1,
47+
scrabbleScore.score.tests.ex2,
48+
scrabbleScore.score.tests.ex3,
49+
scrabbleScore.score.tests.ex4,
50+
scrabbleScore.score.tests.ex5,
51+
scrabbleScore.score.tests.ex6,
52+
scrabbleScore.score.tests.ex7,
53+
scrabbleScore.score.tests.ex8,
54+
scrabbleScore.score.tests.ex9,
55+
scrabbleScore.score.tests.ex10,
56+
scrabbleScore.score.tests.ex11
57+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scrabbleScore.score : Text -> Nat
2+
scrabbleScore.score word = todo "implement score"

0 commit comments

Comments
 (0)