From 87e8d70a0eb701b553ff5801d81bc2f53dbe9b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:43:34 -0800 Subject: [PATCH] add pangram exercise (#190) --- config.json | 8 ++++ .../practice/pangram/.docs/instructions.md | 8 ++++ .../practice/pangram/.docs/introduction.md | 16 +++++++ exercises/practice/pangram/.gitignore | 11 +++++ exercises/practice/pangram/.meta/config.json | 19 ++++++++ exercises/practice/pangram/.meta/example.lfe | 6 +++ exercises/practice/pangram/.meta/tests.toml | 45 +++++++++++++++++++ exercises/practice/pangram/Makefile | 21 +++++++++ exercises/practice/pangram/rebar.config | 11 +++++ exercises/practice/pangram/rebar.lock | 8 ++++ .../practice/pangram/src/pangram.app.src | 11 +++++ exercises/practice/pangram/src/pangram.lfe | 4 ++ .../practice/pangram/test/pangram-tests.lfe | 35 +++++++++++++++ 13 files changed, 203 insertions(+) create mode 100644 exercises/practice/pangram/.docs/instructions.md create mode 100644 exercises/practice/pangram/.docs/introduction.md create mode 100644 exercises/practice/pangram/.gitignore create mode 100644 exercises/practice/pangram/.meta/config.json create mode 100644 exercises/practice/pangram/.meta/example.lfe create mode 100644 exercises/practice/pangram/.meta/tests.toml create mode 100644 exercises/practice/pangram/Makefile create mode 100644 exercises/practice/pangram/rebar.config create mode 100644 exercises/practice/pangram/rebar.lock create mode 100644 exercises/practice/pangram/src/pangram.app.src create mode 100644 exercises/practice/pangram/src/pangram.lfe create mode 100644 exercises/practice/pangram/test/pangram-tests.lfe diff --git a/config.json b/config.json index 6e4cab3a..1f0051ee 100644 --- a/config.json +++ b/config.json @@ -359,6 +359,14 @@ "practices": [], "prerequisites": [], "difficulty": 1 + }, + { + "slug": "pangram", + "name": "Pangram", + "uuid": "d319360a-afef-4b65-be5f-da45d48367cb", + "practices": [], + "prerequisites": [], + "difficulty": 2 } ] }, diff --git a/exercises/practice/pangram/.docs/instructions.md b/exercises/practice/pangram/.docs/instructions.md new file mode 100644 index 00000000..817c872d --- /dev/null +++ b/exercises/practice/pangram/.docs/instructions.md @@ -0,0 +1,8 @@ +# Instructions + +Your task is to figure out if a sentence is a pangram. + +A pangram is a sentence using every letter of the alphabet at least once. +It is case insensitive, so it doesn't matter if a letter is lower-case (e.g. `k`) or upper-case (e.g. `K`). + +For this exercise, a sentence is a pangram if it contains each of the 26 letters in the English alphabet. diff --git a/exercises/practice/pangram/.docs/introduction.md b/exercises/practice/pangram/.docs/introduction.md new file mode 100644 index 00000000..32b6f1fc --- /dev/null +++ b/exercises/practice/pangram/.docs/introduction.md @@ -0,0 +1,16 @@ +# Introduction + +You work for a company that sells fonts through their website. +They'd like to show a different sentence each time someone views a font on their website. +To give a comprehensive sense of the font, the random sentences should use **all** the letters in the English alphabet. + +They're running a competition to get suggestions for sentences that they can use. +You're in charge of checking the submissions to see if they are valid. + +~~~~exercism/note +Pangram comes from Greek, παν γράμμα, pan gramma, which means "every letter". + +The best known English pangram is: + +> The quick brown fox jumps over the lazy dog. +~~~~ diff --git a/exercises/practice/pangram/.gitignore b/exercises/practice/pangram/.gitignore new file mode 100644 index 00000000..6dd20ff0 --- /dev/null +++ b/exercises/practice/pangram/.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/pangram/.meta/config.json b/exercises/practice/pangram/.meta/config.json new file mode 100644 index 00000000..469cad50 --- /dev/null +++ b/exercises/practice/pangram/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "src/pangram.lfe" + ], + "test": [ + "test/pangram-tests.lfe" + ], + "example": [ + ".meta/example.lfe" + ] + }, + "blurb": "Determine if a sentence is a pangram.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Pangram" +} diff --git a/exercises/practice/pangram/.meta/example.lfe b/exercises/practice/pangram/.meta/example.lfe new file mode 100644 index 00000000..0053e380 --- /dev/null +++ b/exercises/practice/pangram/.meta/example.lfe @@ -0,0 +1,6 @@ +(defmodule pangram + (export (pangram? 1))) + +(defun pangram? (sentence) + (ordsets:is_subset (lists:seq #\a #\z) + (ordsets:from_list (string:lowercase sentence)))) diff --git a/exercises/practice/pangram/.meta/tests.toml b/exercises/practice/pangram/.meta/tests.toml new file mode 100644 index 00000000..10b5a335 --- /dev/null +++ b/exercises/practice/pangram/.meta/tests.toml @@ -0,0 +1,45 @@ +# 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. + +[64f61791-508e-4f5c-83ab-05de042b0149] +description = "empty sentence" + +[74858f80-4a4d-478b-8a5e-c6477e4e4e84] +description = "perfect lower case" + +[61288860-35ca-4abe-ba08-f5df76ecbdcd] +description = "only lower case" + +[6564267d-8ac5-4d29-baf2-e7d2e304a743] +description = "missing the letter 'x'" + +[c79af1be-d715-4cdb-a5f2-b2fa3e7e0de0] +description = "missing the letter 'h'" + +[d835ec38-bc8f-48e4-9e36-eb232427b1df] +description = "with underscores" + +[8cc1e080-a178-4494-b4b3-06982c9be2a8] +description = "with numbers" + +[bed96b1c-ff95-45b8-9731-fdbdcb6ede9a] +description = "missing letters replaced by numbers" + +[938bd5d8-ade5-40e2-a2d9-55a338a01030] +description = "mixed case and punctuation" + +[2577bf54-83c8-402d-a64b-a2c0f7bb213a] +description = "case insensitive" +include = false + +[7138e389-83e4-4c6e-8413-1e40a0076951] +description = "a-m and A-M are 26 different characters but not a pangram" +reimplements = "2577bf54-83c8-402d-a64b-a2c0f7bb213a" diff --git a/exercises/practice/pangram/Makefile b/exercises/practice/pangram/Makefile new file mode 100644 index 00000000..fbb5a7de --- /dev/null +++ b/exercises/practice/pangram/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/pangram/rebar.config b/exercises/practice/pangram/rebar.config new file mode 100644 index 00000000..d53487ac --- /dev/null +++ b/exercises/practice/pangram/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/pangram/rebar.lock b/exercises/practice/pangram/rebar.lock new file mode 100644 index 00000000..d5a6b3b9 --- /dev/null +++ b/exercises/practice/pangram/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/pangram/src/pangram.app.src b/exercises/practice/pangram/src/pangram.app.src new file mode 100644 index 00000000..acf711e2 --- /dev/null +++ b/exercises/practice/pangram/src/pangram.app.src @@ -0,0 +1,11 @@ +%% -*- erlang -*- +{application, 'pangram', + [{description, ""}, + {vsn, "0.0.1"}, + {modules, + ['pangram']}, + {registered, []}, + {applications, + [kernel, stdlib]}, + {included_applications, []}, + {env, []}]}. diff --git a/exercises/practice/pangram/src/pangram.lfe b/exercises/practice/pangram/src/pangram.lfe new file mode 100644 index 00000000..5f8d44aa --- /dev/null +++ b/exercises/practice/pangram/src/pangram.lfe @@ -0,0 +1,4 @@ +(defmodule pangram + (export (pangram? 1))) + + ; Please implement the pangram? function. diff --git a/exercises/practice/pangram/test/pangram-tests.lfe b/exercises/practice/pangram/test/pangram-tests.lfe new file mode 100644 index 00000000..750a23a0 --- /dev/null +++ b/exercises/practice/pangram/test/pangram-tests.lfe @@ -0,0 +1,35 @@ +(defmodule pangram-tests + (behaviour ltest-unit) + (export all)) + +(include-lib "ltest/include/ltest-macros.lfe") + +(deftest empty-sentence + (is-not (pangram:pangram? ""))) + +(deftest perfect-lower-case + (is (pangram:pangram? "abcdefghijklmnopqrstuvwxyz"))) + +(deftest only-lower-case + (is (pangram:pangram? "the quick brown fox jumps over the lazy dog"))) + +(deftest missing-the-letter-x + (is-not (pangram:pangram? "a quick movement of the enemy will jeopardize five gunboats"))) + +(deftest missing-the-letter-h + (is-not (pangram:pangram? "five boxing wizards jump quickly at it"))) + +(deftest with-underscores + (is (pangram:pangram? "the_quick_brown_fox_jumps_over_the_lazy_dog"))) + +(deftest with-numbers + (is (pangram:pangram? "the 1 quick brown fox jumps over the 2 lazy dogs"))) + +(deftest missing-letters-replaced-by-numbers + (is-not (pangram:pangram? "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))) + +(deftest mixed-case-and-punctuation + (is (pangram:pangram? "\"Five quacking Zephyrs jolt my wax bed.\""))) + +(deftest a-to-m-and-A-to-M-are-twenty-six-different-characters-but-not-a-pangram + (is-not (pangram:pangram? "abcdefghijklm ABCDEFGHIJKLM")))