Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two-fer #218

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
"math"
]
},
{
"slug": "two-fer",
"name": "Two-Fer",
"uuid": "b186e735-f638-4836-97c1-9c78c5e0078e",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "raindrops",
"name": "Raindrops",
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/two-fer/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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. |
8 changes: 8 additions & 0 deletions exercises/practice/two-fer/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 11 additions & 0 deletions exercises/practice/two-fer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## -*- conf -*-
.rebar3
_build/
ebin/
erl_crash.dump
rebar3.crashdump

tmp
bin/configlet
bin/configlet.exe
CHECKLIST
18 changes: 18 additions & 0 deletions exercises/practice/two-fer/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions exercises/practice/two-fer/.meta/example.lfe
Original file line number Diff line number Diff line change
@@ -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.")))
19 changes: 19 additions & 0 deletions exercises/practice/two-fer/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions exercises/practice/two-fer/Makefile
Original file line number Diff line number Diff line change
@@ -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))))
11 changes: 11 additions & 0 deletions exercises/practice/two-fer/rebar.config
Original file line number Diff line number Diff line change
@@ -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"}]}]}]}.
8 changes: 8 additions & 0 deletions exercises/practice/two-fer/rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{"1.2.0",
[{<<"lfe">>,{pkg,<<"lfe">>,<<"2.1.1">>},0}]}.
[
{pkg_hash,[
{<<"lfe">>, <<"4A888B26172D198DC7A5AFEB897E8248AF7D56E1638D9C8249AAF933AE811B96">>}]},
{pkg_hash_ext,[
{<<"lfe">>, <<"C484D3B655D40DED58BC41B17B22F173711C681BF36063A234A9BAA9506947E1">>}]}
].
11 changes: 11 additions & 0 deletions exercises/practice/two-fer/src/two-fer.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%% -*- erlang -*-
{application, 'two-fer',
[{description, ""},
{vsn, "0.0.1"},
{modules,
['two-fer']},
{registered, []},
{applications,
[kernel, stdlib]},
{included_applications, []},
{env, []}]}.
4 changes: 4 additions & 0 deletions exercises/practice/two-fer/src/two-fer.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(defmodule two-fer
(export (two-fer 1)))

; please define the two-fer function.
14 changes: 14 additions & 0 deletions exercises/practice/two-fer/test/two-fer-tests.lfe
Original file line number Diff line number Diff line change
@@ -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")))