-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scrabble-score-exercise: Added new exercise (#128)
- Loading branch information
1 parent
4a16e10
commit 3b09787
Showing
10 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Instructions | ||
|
||
Your task is to compute a word's Scrabble score by summing the values of its letters. | ||
|
||
The letters are valued as follows: | ||
|
||
| 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 | | ||
|
||
For example, the word "cabbage" is worth 14 points: | ||
|
||
- 3 points for C | ||
- 1 point for A | ||
- 3 points for B | ||
- 3 points for B | ||
- 1 point for A | ||
- 2 points for G | ||
- 1 point for E |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"SimaDovakin" | ||
], | ||
"files": { | ||
"solution": [ | ||
"scrabbleScore.u" | ||
], | ||
"test": [ | ||
"scrabbleScore.test.u" | ||
], | ||
"example": [ | ||
".meta/examples/scrabbleScore.example.u" | ||
] | ||
}, | ||
"blurb": "Given a word, compute the Scrabble score for that word.", | ||
"source": "Inspired by the Extreme Startup game", | ||
"source_url": "https://github.com/rchatley/extreme_startup" | ||
} |
17 changes: 17 additions & 0 deletions
17
exercises/practice/scrabble-score/.meta/examples/scrabbleScore.example.u
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
scrabbleScore.score : Text -> Nat | ||
scrabbleScore.score word = | ||
word | ||
|> toCharList | ||
|> List.foldLeft (total ch -> total + charToScore ch) 0 | ||
|
||
scrabbleScore.charToScore : Char -> Nat | ||
scrabbleScore.charToScore char = | ||
match toUppercase char with | ||
c | List.contains c [?A, ?E, ?I, ?O, ?U, ?L, ?N, ?R, ?S, ?T] -> 1 | ||
c | List.contains c [?D, ?G] -> 2 | ||
c | List.contains c [?B, ?C, ?M, ?P] -> 3 | ||
c | List.contains c [?F, ?H, ?V, ?W, ?Y] -> 4 | ||
c | List.contains c [?J, ?X] -> 8 | ||
c | List.contains c [?Q, ?Z] -> 10 | ||
?K -> 5 | ||
_ -> 0 |
46 changes: 46 additions & 0 deletions
46
exercises/practice/scrabble-score/.meta/testAnnotation.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[ | ||
{ | ||
"name": "scrabbleScore.score.tests.ex1", | ||
"test_code": "expect (1 == scrabbleScore.score \"a\")\n |> Test.label \"lowercase letter\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex2", | ||
"test_code": "expect (1 == scrabbleScore.score \"A\")\n |> Test.label \"uppercase letter\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex3", | ||
"test_code": "expect (4 == scrabbleScore.score \"f\")\n |> Test.label \"valuable letter\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex4", | ||
"test_code": "expect (2 == scrabbleScore.score \"at\")\n |> Test.label \"short word\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex5", | ||
"test_code": "expect (12 == scrabbleScore.score \"zoo\")\n |> Test.label \"short, valuable word\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex6", | ||
"test_code": "expect (6 == scrabbleScore.score \"street\")\n |> Test.label \"medium word\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex7", | ||
"test_code": "expect (22 == scrabbleScore.score \"quirky\")\n |> Test.label \"medium, valuable word\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex8", | ||
"test_code": "expect (41 == scrabbleScore.score \"OxyphenButazone\")\n |> Test.label \"long, mixed-case word\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex9", | ||
"test_code": "expect (8 == scrabbleScore.score \"pinata\")\n |> Test.label \"english-like word\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex10", | ||
"test_code": "expect (0 == scrabbleScore.score \"\")\n |> Test.label \"empty input\"" | ||
}, | ||
{ | ||
"name": "scrabbleScore.score.tests.ex11", | ||
"test_code": "expect (87 == scrabbleScore.score \"abcdefghijklmnopqrstuvwxyz\")\n |> Test.label \"entire alphabet available\"" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Testing transcript for scrabble-score exercise | ||
|
||
```ucm | ||
.> load ./scrabbleScore.u | ||
.> add | ||
.> load ./scrabbleScore.test.u | ||
.> add | ||
.> move.term scrabbleScore.tests tests | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[f46cda29-1ca5-4ef2-bd45-388a767e3db2] | ||
description = "lowercase letter" | ||
|
||
[f7794b49-f13e-45d1-a933-4e48459b2201] | ||
description = "uppercase letter" | ||
|
||
[eaba9c76-f9fa-49c9-a1b0-d1ba3a5b31fa] | ||
description = "valuable letter" | ||
|
||
[f3c8c94e-bb48-4da2-b09f-e832e103151e] | ||
description = "short word" | ||
|
||
[71e3d8fa-900d-4548-930e-68e7067c4615] | ||
description = "short, valuable word" | ||
|
||
[d3088ad9-570c-4b51-8764-c75d5a430e99] | ||
description = "medium word" | ||
|
||
[fa20c572-ad86-400a-8511-64512daac352] | ||
description = "medium, valuable word" | ||
|
||
[9336f0ba-9c2b-4fa0-bd1c-2e2d328cf967] | ||
description = "long, mixed-case word" | ||
|
||
[1e34e2c3-e444-4ea7-b598-3c2b46fd2c10] | ||
description = "english-like word" | ||
|
||
[4efe3169-b3b6-4334-8bae-ff4ef24a7e4f] | ||
description = "empty input" | ||
|
||
[3b305c1c-f260-4e15-a5b5-cb7d3ea7c3d7] | ||
description = "entire alphabet available" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
scrabbleScore.score.tests.ex1 = | ||
expect (1 == scrabbleScore.score "a") | ||
|> Test.label "lowercase letter" | ||
|
||
scrabbleScore.score.tests.ex2 = | ||
expect (1 == scrabbleScore.score "A") | ||
|> Test.label "uppercase letter" | ||
|
||
scrabbleScore.score.tests.ex3 = | ||
expect (4 == scrabbleScore.score "f") | ||
|> Test.label "valuable letter" | ||
|
||
scrabbleScore.score.tests.ex4 = | ||
expect (2 == scrabbleScore.score "at") | ||
|> Test.label "short word" | ||
|
||
scrabbleScore.score.tests.ex5 = | ||
expect (12 == scrabbleScore.score "zoo") | ||
|> Test.label "short, valuable word" | ||
|
||
scrabbleScore.score.tests.ex6 = | ||
expect (6 == scrabbleScore.score "street") | ||
|> Test.label "medium word" | ||
|
||
scrabbleScore.score.tests.ex7 = | ||
expect (22 == scrabbleScore.score "quirky") | ||
|> Test.label "medium, valuable word" | ||
|
||
scrabbleScore.score.tests.ex8 = | ||
expect (41 == scrabbleScore.score "OxyphenButazone") | ||
|> Test.label "long, mixed-case word" | ||
|
||
scrabbleScore.score.tests.ex9 = | ||
expect (8 == scrabbleScore.score "pinata") | ||
|> Test.label "english-like word" | ||
|
||
scrabbleScore.score.tests.ex10 = | ||
expect (0 == scrabbleScore.score "") | ||
|> Test.label "empty input" | ||
|
||
scrabbleScore.score.tests.ex11 = | ||
expect (87 == scrabbleScore.score "abcdefghijklmnopqrstuvwxyz") | ||
|> Test.label "entire alphabet available" | ||
|
||
test> scrabbleScore.tests = runAll [ | ||
scrabbleScore.score.tests.ex1, | ||
scrabbleScore.score.tests.ex2, | ||
scrabbleScore.score.tests.ex3, | ||
scrabbleScore.score.tests.ex4, | ||
scrabbleScore.score.tests.ex5, | ||
scrabbleScore.score.tests.ex6, | ||
scrabbleScore.score.tests.ex7, | ||
scrabbleScore.score.tests.ex8, | ||
scrabbleScore.score.tests.ex9, | ||
scrabbleScore.score.tests.ex10, | ||
scrabbleScore.score.tests.ex11 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
scrabbleScore.score : Text -> Nat | ||
scrabbleScore.score word = todo "implement score" |