From 3174c0ab150aa8473b0707f231c60e2d2c90439f Mon Sep 17 00:00:00 2001 From: Pierre Thierry Date: Mon, 5 Feb 2024 23:29:52 +0100 Subject: [PATCH] Add Acronym practice exercise --- config.json | 10 ++++++- .../practice/acronym/.docs/instructions.md | 17 +++++++++++ exercises/practice/acronym/.gitignore | 11 +++++++ exercises/practice/acronym/.meta/config.json | 24 +++++++++++++++ exercises/practice/acronym/.meta/example.lfe | 26 ++++++++++++++++ exercises/practice/acronym/.meta/tests.toml | 30 +++++++++++++++++++ exercises/practice/acronym/Makefile | 21 +++++++++++++ exercises/practice/acronym/rebar.config | 11 +++++++ exercises/practice/acronym/rebar.lock | 8 +++++ .../practice/acronym/src/acronym.app.src | 11 +++++++ exercises/practice/acronym/src/acronym.lfe | 5 ++++ .../practice/acronym/test/acronym-tests.lfe | 24 +++++++++++++++ 12 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 exercises/practice/acronym/.docs/instructions.md create mode 100644 exercises/practice/acronym/.gitignore create mode 100644 exercises/practice/acronym/.meta/config.json create mode 100644 exercises/practice/acronym/.meta/example.lfe create mode 100644 exercises/practice/acronym/.meta/tests.toml create mode 100644 exercises/practice/acronym/Makefile create mode 100644 exercises/practice/acronym/rebar.config create mode 100644 exercises/practice/acronym/rebar.lock create mode 100644 exercises/practice/acronym/src/acronym.app.src create mode 100644 exercises/practice/acronym/src/acronym.lfe create mode 100644 exercises/practice/acronym/test/acronym-tests.lfe diff --git a/config.json b/config.json index c134eb1b..311d340c 100644 --- a/config.json +++ b/config.json @@ -45,7 +45,6 @@ "prerequisites": [], "difficulty": 1, "topics": [ - "strings" ] }, { @@ -57,6 +56,15 @@ "difficulty": 1, "status": "deprecated" }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "d3b82743-950f-4577-ab3a-655ff3522c6b", + "practices": [], + "prerequisites": [ + ], + "difficulty": 2 + }, { "slug": "allergies", "name": "Allergies", diff --git a/exercises/practice/acronym/.docs/instructions.md b/exercises/practice/acronym/.docs/instructions.md new file mode 100644 index 00000000..c62fc3e8 --- /dev/null +++ b/exercises/practice/acronym/.docs/instructions.md @@ -0,0 +1,17 @@ +# Instructions + +Convert a phrase to its acronym. + +Techies love their TLA (Three Letter Acronyms)! + +Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). + +Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input. + +For example: + +|Input|Output| +|-|-| +|As Soon As Possible|ASAP| +|Liquid-crystal display|LCD| +|Thank George It's Friday!|TGIF| diff --git a/exercises/practice/acronym/.gitignore b/exercises/practice/acronym/.gitignore new file mode 100644 index 00000000..6dd20ff0 --- /dev/null +++ b/exercises/practice/acronym/.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/acronym/.meta/config.json b/exercises/practice/acronym/.meta/config.json new file mode 100644 index 00000000..7f4e7beb --- /dev/null +++ b/exercises/practice/acronym/.meta/config.json @@ -0,0 +1,24 @@ +{ + "authors": [ + "kephas" + ], + "contributors": [ + ], + "files": { + "solution": [ + "src/acronym.lfe" + ], + "test": [ + "test/acronym-tests.lfe" + ], + "example": [ + ".meta/example.lfe" + ], + "invalidator": [ + "rebar.config" + ] + }, + "blurb": "Convert a long phrase to its acronym.", + "source": "Julien Vanier", + "source_url": "https://github.com/monkbroc" +} diff --git a/exercises/practice/acronym/.meta/example.lfe b/exercises/practice/acronym/.meta/example.lfe new file mode 100644 index 00000000..deca455a --- /dev/null +++ b/exercises/practice/acronym/.meta/example.lfe @@ -0,0 +1,26 @@ +(defmodule acronym + (export (abbreviate 1))) + +(defun upper (char) + (string:to_upper char)) + +(defun upper? (char) + (!= 'nomatch (re:run (list char) "\\p{Lu}"))) + +(defun break? + ((#\ ) 'true) + ((#\-) 'true) + ((_) 'false)) + +(defun abbreviate + (((cons c1 (cons c2 cs))) + (cond + ((and (upper? c1) (upper? c2)) + (abbreviate (cons c1 cs))) + ((upper? c1) + (cons c1 (abbreviate (cons c2 cs)))) + ((break? c1) + (abbreviate (cons (upper c2) cs))) + ('true + (abbreviate (cons c2 cs))))) + ((_) ())) diff --git a/exercises/practice/acronym/.meta/tests.toml b/exercises/practice/acronym/.meta/tests.toml new file mode 100644 index 00000000..157cae14 --- /dev/null +++ b/exercises/practice/acronym/.meta/tests.toml @@ -0,0 +1,30 @@ +# This is an auto-generated file. Regular comments will be removed when this +# file is regenerated. Regenerating will not touch any manually added keys, +# so comments can be added in a "comment" key. + +[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4] +description = "basic" + +[79ae3889-a5c0-4b01-baf0-232d31180c08] +description = "lowercase words" + +[ec7000a7-3931-4a17-890e-33ca2073a548] +description = "punctuation" + +[32dd261c-0c92-469a-9c5c-b192e94a63b0] +description = "all caps word" + +[ae2ac9fa-a606-4d05-8244-3bcc4659c1d4] +description = "punctuation without whitespace" + +[0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9] +description = "very long abbreviation" + +[6a078f49-c68d-4b7b-89af-33a1a98c28cc] +description = "consecutive delimiters" + +[5118b4b1-4572-434c-8d57-5b762e57973e] +description = "apostrophes" + +[adc12eab-ec2d-414f-b48c-66a4fc06cdef] +description = "underscore emphasis" diff --git a/exercises/practice/acronym/Makefile b/exercises/practice/acronym/Makefile new file mode 100644 index 00000000..fbb5a7de --- /dev/null +++ b/exercises/practice/acronym/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/acronym/rebar.config b/exercises/practice/acronym/rebar.config new file mode 100644 index 00000000..d53487ac --- /dev/null +++ b/exercises/practice/acronym/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/acronym/rebar.lock b/exercises/practice/acronym/rebar.lock new file mode 100644 index 00000000..d5a6b3b9 --- /dev/null +++ b/exercises/practice/acronym/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/acronym/src/acronym.app.src b/exercises/practice/acronym/src/acronym.app.src new file mode 100644 index 00000000..96bdb289 --- /dev/null +++ b/exercises/practice/acronym/src/acronym.app.src @@ -0,0 +1,11 @@ +%% -*- erlang -*- +{application, 'acronym', + [{description, ""}, + {vsn, "0.0.1"}, + {modules, + ['acronym']}, + {registered, []}, + {applications, + [kernel, stdlib]}, + {included_applications, []}, + {env, []}]}. diff --git a/exercises/practice/acronym/src/acronym.lfe b/exercises/practice/acronym/src/acronym.lfe new file mode 100644 index 00000000..97ed9f21 --- /dev/null +++ b/exercises/practice/acronym/src/acronym.lfe @@ -0,0 +1,5 @@ +(defmodule acronym + (export (abbreviate 1))) + +(defun abbreviate (str) + (throw "Please implement the abbreviate function")) diff --git a/exercises/practice/acronym/test/acronym-tests.lfe b/exercises/practice/acronym/test/acronym-tests.lfe new file mode 100644 index 00000000..483d6dec --- /dev/null +++ b/exercises/practice/acronym/test/acronym-tests.lfe @@ -0,0 +1,24 @@ +(defmodule acronym-tests + (behaviour ltest-unit) + (export all)) + +(include-lib "ltest/include/ltest-macros.lfe") + +(defun acronyms_test_ () + (lists:map #'make-test/1 (cases))) + +(defun make-test + (((tuple description input expected)) + (tuple description (lambda () (is-equal expected (acronym:abbreviate input)))))) + +(defun cases () + (list + (tuple "basic" "Portable Network Graphics" "PNG") + (tuple "lowercase words" "Ruby on Rails" "ROR") + (tuple "punctuation" "First In, First Out" "FIFO") + (tuple "all caps word" "GNU Image Manipulation Program" "GIMP") + (tuple "punctuation without whitespace" "Complementary metal-oxide semiconductor" "CMOS") + (tuple "very long abbreviation" "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" "ROTFLSHTMDCOALM") + (tuple "consecutive delimiters" "Something - I made up from thin air" "SIMUFTA") + (tuple "apostrophes" "Halley's Comet" "HC") + (tuple "underscore emphasis" "The Road _Not_ Taken" "TRNT")))