From 29dbc91b99724767741c506e0082ca5180372212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:58:38 -0700 Subject: [PATCH] Add two-fer (#218) --- config.json | 8 +++++++ .../practice/two-fer/.docs/instructions.md | 24 +++++++++++++++++++ .../practice/two-fer/.docs/introduction.md | 8 +++++++ exercises/practice/two-fer/.gitignore | 11 +++++++++ exercises/practice/two-fer/.meta/config.json | 18 ++++++++++++++ exercises/practice/two-fer/.meta/example.lfe | 6 +++++ exercises/practice/two-fer/.meta/tests.toml | 19 +++++++++++++++ exercises/practice/two-fer/Makefile | 21 ++++++++++++++++ exercises/practice/two-fer/rebar.config | 11 +++++++++ exercises/practice/two-fer/rebar.lock | 8 +++++++ .../practice/two-fer/src/two-fer.app.src | 11 +++++++++ exercises/practice/two-fer/src/two-fer.lfe | 4 ++++ .../practice/two-fer/test/two-fer-tests.lfe | 14 +++++++++++ 13 files changed, 163 insertions(+) create mode 100644 exercises/practice/two-fer/.docs/instructions.md create mode 100644 exercises/practice/two-fer/.docs/introduction.md create mode 100644 exercises/practice/two-fer/.gitignore create mode 100644 exercises/practice/two-fer/.meta/config.json create mode 100644 exercises/practice/two-fer/.meta/example.lfe create mode 100644 exercises/practice/two-fer/.meta/tests.toml create mode 100644 exercises/practice/two-fer/Makefile create mode 100644 exercises/practice/two-fer/rebar.config create mode 100644 exercises/practice/two-fer/rebar.lock create mode 100644 exercises/practice/two-fer/src/two-fer.app.src create mode 100644 exercises/practice/two-fer/src/two-fer.lfe create mode 100644 exercises/practice/two-fer/test/two-fer-tests.lfe diff --git a/config.json b/config.json index b53e6e4b..f59bb289 100644 --- a/config.json +++ b/config.json @@ -226,6 +226,14 @@ "math" ] }, + { + "slug": "two-fer", + "name": "Two-Fer", + "uuid": "b186e735-f638-4836-97c1-9c78c5e0078e", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "raindrops", "name": "Raindrops", diff --git a/exercises/practice/two-fer/.docs/instructions.md b/exercises/practice/two-fer/.docs/instructions.md new file mode 100644 index 00000000..adc53487 --- /dev/null +++ b/exercises/practice/two-fer/.docs/instructions.md @@ -0,0 +1,24 @@ +# Instructions + +Your task is to determine what you will say as you give away the extra cookie. + +If you know the person's name (e.g. if they're named Do-yun), then you will say: + +```text +One for Do-yun, one for me. +``` + +If you don't know the person's name, you will say _you_ instead. + +```text +One for you, one for me. +``` + +Here are some examples: + +| Name | Dialogue | +| :----- | :-------------------------- | +| Alice | One for Alice, one for me. | +| Bohdan | One for Bohdan, one for me. | +| | One for you, one for me. | +| Zaphod | One for Zaphod, one for me. | diff --git a/exercises/practice/two-fer/.docs/introduction.md b/exercises/practice/two-fer/.docs/introduction.md new file mode 100644 index 00000000..5947a223 --- /dev/null +++ b/exercises/practice/two-fer/.docs/introduction.md @@ -0,0 +1,8 @@ +# Introduction + +In some English accents, when you say "two for" quickly, it sounds like "two fer". +Two-for-one is a way of saying that if you buy one, you also get one for free. +So the phrase "two-fer" often implies a two-for-one offer. + +Imagine a bakery that has a holiday offer where you can buy two cookies for the price of one ("two-fer one!"). +You take the offer and (very generously) decide to give the extra cookie to someone else in the queue. diff --git a/exercises/practice/two-fer/.gitignore b/exercises/practice/two-fer/.gitignore new file mode 100644 index 00000000..6dd20ff0 --- /dev/null +++ b/exercises/practice/two-fer/.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/two-fer/.meta/config.json b/exercises/practice/two-fer/.meta/config.json new file mode 100644 index 00000000..b7fa02f9 --- /dev/null +++ b/exercises/practice/two-fer/.meta/config.json @@ -0,0 +1,18 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "src/two-fer.lfe" + ], + "test": [ + "test/two-fer-tests.lfe" + ], + "example": [ + ".meta/example.lfe" + ] + }, + "blurb": "Create a sentence of the form \"One for X, one for me.\".", + "source_url": "https://github.com/exercism/problem-specifications/issues/757" +} diff --git a/exercises/practice/two-fer/.meta/example.lfe b/exercises/practice/two-fer/.meta/example.lfe new file mode 100644 index 00000000..330a0457 --- /dev/null +++ b/exercises/practice/two-fer/.meta/example.lfe @@ -0,0 +1,6 @@ +(defmodule two-fer + (export (two-fer 1))) + +(defun two-fer + (("") "One for you, one for me.") + ((name) (++ "One for " name ", one for me."))) diff --git a/exercises/practice/two-fer/.meta/tests.toml b/exercises/practice/two-fer/.meta/tests.toml new file mode 100644 index 00000000..d0e38573 --- /dev/null +++ b/exercises/practice/two-fer/.meta/tests.toml @@ -0,0 +1,19 @@ +# 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. + +[1cf3e15a-a3d7-4a87-aeb3-ba1b43bc8dce] +description = "no name given" + +[b4c6dbb8-b4fb-42c2-bafd-10785abe7709] +description = "a name given" + +[3549048d-1a6e-4653-9a79-b0bda163e8d5] +description = "another name given" diff --git a/exercises/practice/two-fer/Makefile b/exercises/practice/two-fer/Makefile new file mode 100644 index 00000000..fbb5a7de --- /dev/null +++ b/exercises/practice/two-fer/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/two-fer/rebar.config b/exercises/practice/two-fer/rebar.config new file mode 100644 index 00000000..d53487ac --- /dev/null +++ b/exercises/practice/two-fer/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/two-fer/rebar.lock b/exercises/practice/two-fer/rebar.lock new file mode 100644 index 00000000..d5a6b3b9 --- /dev/null +++ b/exercises/practice/two-fer/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/two-fer/src/two-fer.app.src b/exercises/practice/two-fer/src/two-fer.app.src new file mode 100644 index 00000000..c8b58f3c --- /dev/null +++ b/exercises/practice/two-fer/src/two-fer.app.src @@ -0,0 +1,11 @@ +%% -*- erlang -*- +{application, 'two-fer', + [{description, ""}, + {vsn, "0.0.1"}, + {modules, + ['two-fer']}, + {registered, []}, + {applications, + [kernel, stdlib]}, + {included_applications, []}, + {env, []}]}. diff --git a/exercises/practice/two-fer/src/two-fer.lfe b/exercises/practice/two-fer/src/two-fer.lfe new file mode 100644 index 00000000..085b7cb7 --- /dev/null +++ b/exercises/practice/two-fer/src/two-fer.lfe @@ -0,0 +1,4 @@ +(defmodule two-fer + (export (two-fer 1))) + + ; please define the two-fer function. diff --git a/exercises/practice/two-fer/test/two-fer-tests.lfe b/exercises/practice/two-fer/test/two-fer-tests.lfe new file mode 100644 index 00000000..df2c064d --- /dev/null +++ b/exercises/practice/two-fer/test/two-fer-tests.lfe @@ -0,0 +1,14 @@ +(defmodule two-fer-tests + (behaviour ltest-unit) + (export all)) + +(include-lib "ltest/include/ltest-macros.lfe") + +(deftest no-name-given + (is-equal "One for you, one for me." (two-fer:two-fer ""))) + +(deftest a-name-given + (is-equal "One for Alice, one for me." (two-fer:two-fer "Alice"))) + +(deftest another-name-given + (is-equal "One for Bob, one for me." (two-fer:two-fer "Bob")))