From 87297874f6f9f7deb9d6bcaf85cce158de481e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Tue, 6 Feb 2024 21:36:07 -0800 Subject: [PATCH] Add scrabble-score --- config.json | 8 ++++ .../scrabble-score/.docs/instructions.md | 40 +++++++++++++++++ exercises/practice/scrabble-score/.gitignore | 11 +++++ .../practice/scrabble-score/.meta/config.json | 19 ++++++++ .../practice/scrabble-score/.meta/example.lfe | 34 +++++++++++++++ .../practice/scrabble-score/.meta/tests.toml | 43 +++++++++++++++++++ exercises/practice/scrabble-score/Makefile | 21 +++++++++ .../practice/scrabble-score/rebar.config | 11 +++++ exercises/practice/scrabble-score/rebar.lock | 8 ++++ .../scrabble-score/src/scrabble-score.app.src | 11 +++++ .../scrabble-score/src/scrabble-score.lfe | 4 ++ .../test/scrabble-score-tests.lfe | 38 ++++++++++++++++ 12 files changed, 248 insertions(+) create mode 100644 exercises/practice/scrabble-score/.docs/instructions.md create mode 100644 exercises/practice/scrabble-score/.gitignore create mode 100644 exercises/practice/scrabble-score/.meta/config.json create mode 100644 exercises/practice/scrabble-score/.meta/example.lfe create mode 100644 exercises/practice/scrabble-score/.meta/tests.toml create mode 100644 exercises/practice/scrabble-score/Makefile create mode 100644 exercises/practice/scrabble-score/rebar.config create mode 100644 exercises/practice/scrabble-score/rebar.lock create mode 100644 exercises/practice/scrabble-score/src/scrabble-score.app.src create mode 100644 exercises/practice/scrabble-score/src/scrabble-score.lfe create mode 100644 exercises/practice/scrabble-score/test/scrabble-score-tests.lfe diff --git a/config.json b/config.json index 3293408e..c134eb1b 100644 --- a/config.json +++ b/config.json @@ -335,6 +335,14 @@ "practices": [], "prerequisites": [], "difficulty": 2 + }, + { + "slug": "scrabble-score", + "name": "Scrabble Score", + "uuid": "2197494b-94a8-45b4-932d-3f35c0305a62", + "practices": [], + "prerequisites": [], + "difficulty": 2 } ] }, diff --git a/exercises/practice/scrabble-score/.docs/instructions.md b/exercises/practice/scrabble-score/.docs/instructions.md new file mode 100644 index 00000000..3f986c94 --- /dev/null +++ b/exercises/practice/scrabble-score/.docs/instructions.md @@ -0,0 +1,40 @@ +# Instructions + +Given a word, compute the Scrabble score for that word. + +## Letter Values + +You'll need these: + +```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: + +- 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. diff --git a/exercises/practice/scrabble-score/.gitignore b/exercises/practice/scrabble-score/.gitignore new file mode 100644 index 00000000..6dd20ff0 --- /dev/null +++ b/exercises/practice/scrabble-score/.gitignore @@ -0,0 +1,11 @@ +## -*- conf -*- +.rebar3 +_build/ +ebin/ +erl_crash.dump +rebar3.crashdump + +tmp +bin/configlet +bin/configlet.exe +CHECKLIST diff --git a/exercises/practice/scrabble-score/.meta/config.json b/exercises/practice/scrabble-score/.meta/config.json new file mode 100644 index 00000000..aed9fb22 --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "src/scrabble-score.lfe" + ], + "test": [ + "test/scrabble-score-tests.lfe" + ], + "example": [ + ".meta/example.lfe" + ] + }, + "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/example.lfe b/exercises/practice/scrabble-score/.meta/example.lfe new file mode 100644 index 00000000..b4cb1036 --- /dev/null +++ b/exercises/practice/scrabble-score/.meta/example.lfe @@ -0,0 +1,34 @@ +(defmodule scrabble-score + (export (score 1))) + +(defun score (word) + (lists:sum (lists:map #'value-of/1 (string:lowercase word)))) + +(defun value-of + ([#\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) + ([_] 0)) diff --git a/exercises/practice/scrabble-score/.meta/tests.toml b/exercises/practice/scrabble-score/.meta/tests.toml new file mode 100644 index 00000000..33a873c0 --- /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/Makefile b/exercises/practice/scrabble-score/Makefile new file mode 100644 index 00000000..fbb5a7de --- /dev/null +++ b/exercises/practice/scrabble-score/Makefile @@ -0,0 +1,21 @@ +ERL := $(shell which erl) +REBAR3 := $(shell which rebar3) + +null := +space := $(null) # +comma := , + +ifeq ($(ERL),) + $(error Can't find Erlang executable 'erl') +else ifeq ($(REBAR3),) + $(error Can't find rebar3) +endif + +compile: ; $(REBAR3) compile + +clean: ; $(REBAR3) clean + +.PHONY: test +test: + $(REBAR3) eunit \ + -m $(subst $(space),$(comma),$(basename $(notdir $(wildcard test/*.lfe)))) diff --git a/exercises/practice/scrabble-score/rebar.config b/exercises/practice/scrabble-score/rebar.config new file mode 100644 index 00000000..d53487ac --- /dev/null +++ b/exercises/practice/scrabble-score/rebar.config @@ -0,0 +1,11 @@ +{plugins, [{rebar3_lfe, "0.4.3"}]}. + +{provider_hooks, [{post, [{compile, {lfe, compile}}]}]}. + +{deps, [{lfe, "2.1.1"}]}. + +{profiles, + [{test, + [{eunit_compile_opts, [{src_dirs, ["src", "test"]}]}, + {deps, + [{ltest, "0.13.3"}]}]}]}. diff --git a/exercises/practice/scrabble-score/rebar.lock b/exercises/practice/scrabble-score/rebar.lock new file mode 100644 index 00000000..d5a6b3b9 --- /dev/null +++ b/exercises/practice/scrabble-score/rebar.lock @@ -0,0 +1,8 @@ +{"1.2.0", +[{<<"lfe">>,{pkg,<<"lfe">>,<<"2.1.1">>},0}]}. +[ +{pkg_hash,[ + {<<"lfe">>, <<"4A888B26172D198DC7A5AFEB897E8248AF7D56E1638D9C8249AAF933AE811B96">>}]}, +{pkg_hash_ext,[ + {<<"lfe">>, <<"C484D3B655D40DED58BC41B17B22F173711C681BF36063A234A9BAA9506947E1">>}]} +]. diff --git a/exercises/practice/scrabble-score/src/scrabble-score.app.src b/exercises/practice/scrabble-score/src/scrabble-score.app.src new file mode 100644 index 00000000..98e5bfc3 --- /dev/null +++ b/exercises/practice/scrabble-score/src/scrabble-score.app.src @@ -0,0 +1,11 @@ +%% -*- erlang -*- +{application, 'scrabble-score', + [{description, ""}, + {vsn, "0.0.1"}, + {modules, + ['scrabble-score']}, + {registered, []}, + {applications, + [kernel, stdlib]}, + {included_applications, []}, + {env, []}]}. diff --git a/exercises/practice/scrabble-score/src/scrabble-score.lfe b/exercises/practice/scrabble-score/src/scrabble-score.lfe new file mode 100644 index 00000000..08effb24 --- /dev/null +++ b/exercises/practice/scrabble-score/src/scrabble-score.lfe @@ -0,0 +1,4 @@ +(defmodule scrabble-score + (export (score 1))) + + ; Please implement the `score` function. diff --git a/exercises/practice/scrabble-score/test/scrabble-score-tests.lfe b/exercises/practice/scrabble-score/test/scrabble-score-tests.lfe new file mode 100644 index 00000000..496f2abc --- /dev/null +++ b/exercises/practice/scrabble-score/test/scrabble-score-tests.lfe @@ -0,0 +1,38 @@ +(defmodule scrabble-score-tests + (behaviour ltest-unit) + (export all)) + +(include-lib "ltest/include/ltest-macros.lfe") + +(deftest lowercase-letter + (is-equal (scrabble-score:score "a") 1)) + +(deftest uppercase-letter + (is-equal (scrabble-score:score "A") 1)) + +(deftest valuable-letter + (is-equal (scrabble-score:score "f") 4)) + +(deftest short-word + (is-equal (scrabble-score:score "at") 2)) + +(deftest short-valuable-word + (is-equal (scrabble-score:score "zoo") 12)) + +(deftest medium-word + (is-equal (scrabble-score:score "street") 6)) + +(deftest medium-valuable-word + (is-equal (scrabble-score:score "quirky") 22)) + +(deftest long-mixed-case-word + (is-equal (scrabble-score:score "OxyphenButazone") 41)) + +(deftest english-like-word + (is-equal (scrabble-score:score "pinata") 8)) + +(deftest empty-input + (is-equal (scrabble-score:score "") 0)) + +(deftest entire-alphabet-available + (is-equal (scrabble-score:score "abcdefghijklmnopqrstuvwxyz") 87))