diff --git a/config.json b/config.json index 7437dd2..a24a79a 100644 --- a/config.json +++ b/config.json @@ -390,6 +390,14 @@ "practices": [], "prerequisites": [], "difficulty": 4 + }, + { + "slug": "scrabble-score", + "name": "Scrabble Score", + "uuid": "b03f5c6e-86c4-4aa7-92cc-7587dd5dc3d3", + "practices": [], + "prerequisites": [], + "difficulty": 4 } ] }, diff --git a/exercises/practice/scrabble-score/.docs/instructions.md b/exercises/practice/scrabble-score/.docs/instructions.md new file mode 100644 index 0000000..738f928 --- /dev/null +++ b/exercises/practice/scrabble-score/.docs/instructions.md @@ -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 diff --git a/exercises/practice/scrabble-score/.docs/introduction.md b/exercises/practice/scrabble-score/.docs/introduction.md new file mode 100644 index 0000000..8821f24 --- /dev/null +++ b/exercises/practice/scrabble-score/.docs/introduction.md @@ -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 diff --git a/exercises/practice/scrabble-score/.meta/config.json b/exercises/practice/scrabble-score/.meta/config.json new file mode 100644 index 0000000..347411a --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/config.json @@ -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" +} diff --git a/exercises/practice/scrabble-score/.meta/examples/scrabbleScore.example.u b/exercises/practice/scrabble-score/.meta/examples/scrabbleScore.example.u new file mode 100644 index 0000000..226c21f --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/examples/scrabbleScore.example.u @@ -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 diff --git a/exercises/practice/scrabble-score/.meta/testAnnotation.json b/exercises/practice/scrabble-score/.meta/testAnnotation.json new file mode 100644 index 0000000..1cb179a --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/testAnnotation.json @@ -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\"" + } +] diff --git a/exercises/practice/scrabble-score/.meta/testLoader.md b/exercises/practice/scrabble-score/.meta/testLoader.md new file mode 100644 index 0000000..b879cff --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/testLoader.md @@ -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 +``` diff --git a/exercises/practice/scrabble-score/.meta/tests.toml b/exercises/practice/scrabble-score/.meta/tests.toml new file mode 100644 index 0000000..33a873c --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/tests.toml @@ -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" diff --git a/exercises/practice/scrabble-score/scrabbleScore.test.u b/exercises/practice/scrabble-score/scrabbleScore.test.u new file mode 100644 index 0000000..2779a23 --- /dev/null +++ b/exercises/practice/scrabble-score/scrabbleScore.test.u @@ -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 +] diff --git a/exercises/practice/scrabble-score/scrabbleScore.u b/exercises/practice/scrabble-score/scrabbleScore.u new file mode 100644 index 0000000..7bc2a69 --- /dev/null +++ b/exercises/practice/scrabble-score/scrabbleScore.u @@ -0,0 +1,2 @@ +scrabbleScore.score : Text -> Nat +scrabbleScore.score word = todo "implement score"