Skip to content

Commit 04cd434

Browse files
authored
Merge pull request #251 from verdammelt/two-fer
Add two-fer exercise.
2 parents 43e9a4f + 3197c20 commit 04cd434

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

config.json

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
"strings"
1919
]
2020
},
21+
{
22+
"slug": "two-fer",
23+
"uuid": "b80ab7d9-6152-4351-b405-07c2fb071962",
24+
"core": true,
25+
"unlocked_by": null,
26+
"difficulty": 1,
27+
"topics": [
28+
"strings",
29+
"optional_values",
30+
"text_formatting"
31+
]
32+
},
2133
{
2234
"slug": "luhn",
2335
"uuid": "7cc9d827-b08e-437d-826e-244f220feca0",

exercises/two-fer/README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Two Fer
2+
3+
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
4+
5+
Given a name, return a string with the message:
6+
7+
```text
8+
One for X, one for me.
9+
```
10+
11+
Where X is the given name.
12+
13+
However, if the name is missing, return the string:
14+
15+
```text
16+
One for you, one for me.
17+
```
18+
19+
Here are some examples:
20+
21+
|Name |String to return
22+
|:-------|:------------------
23+
|Alice |One for Alice, one for me.
24+
|Bob |One for Bob, one for me.
25+
| |One for you, one for me.
26+
|Zaphod |One for Zaphod, one for me.
27+
28+
## Setup
29+
30+
Check out [Installing Common
31+
Lisp](https://exercism.io/tracks/common-lisp/installation) for
32+
instructions to get started or take a look at the guides available in
33+
the [track's side bar](https://exercism.io/my/tracks/common-lisp).
34+
35+
## Formatting
36+
37+
While Common Lisp doesn't care about indentation and layout of code,
38+
nor whether you use spaces or tabs, this is an important consideration
39+
for submissions to exercism.io. Excercism.io's code widget cannot
40+
handle mixing of tab and space characters well so using only spaces is recommended to make
41+
the code more readable to the human reviewers. Please review your
42+
editors settings on how to accomplish this. Below are instructions for
43+
popular editors for Common Lisp.
44+
45+
### VIM
46+
47+
Use the following commands to ensure VIM uses only spaces for
48+
indentation:
49+
50+
```vimscript
51+
:set tabstop=2
52+
:set shiftwidth=2
53+
:set expandtab
54+
```
55+
56+
(or as a oneliner `:set tabstop=2 shiftwidth=2 expandtab`). This can
57+
be added to your `~/.vimrc` file to use it all the time.
58+
59+
### Emacs
60+
61+
Emacs is very well suited for editing Common Lisp and has many
62+
powerful add-on packages available. The only thing that one needs to
63+
do with a stock emacs to make it work well with exercism.io is to
64+
evaluate the following code:
65+
66+
`(setq-default indent-tabs-mode nil)`
67+
68+
This can be placed in your `~/.emacs` (or `~/.emacs.d/init.el`) in
69+
order to have it set whenever Emacs is launched.
70+
71+
One suggested add-on for Emacs and Common Lisp is
72+
[SLIME](https://github.com/slime/slime) which offers tight integration
73+
with the REPL; making iterative coding and testing very easy.
74+
75+
## Source
76+
77+
[https://github.com/exercism/problem-specifications/issues/757](https://github.com/exercism/problem-specifications/issues/757)
78+
79+
## Submitting Incomplete Solutions
80+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

exercises/two-fer/example.lisp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(in-package #:cl-user)
2+
(defpackage #:two-fer
3+
(:use #:cl)
4+
(:export #:twofer))
5+
(in-package #:two-fer)
6+
7+
(defun twofer (name)
8+
(format nil "One for ~a, one for me." (or name "you")))

exercises/two-fer/two-fer-test.lisp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
;;;
2+
;;; two-fer v1.2.0
3+
;;;
4+
(ql:quickload "lisp-unit")
5+
#-xlisp-test (load "two-fer")
6+
7+
(defpackage #:two-fer-test
8+
(:use #:common-lisp #:lisp-unit))
9+
(in-package #:two-fer-test)
10+
11+
(define-test
12+
no-name-given
13+
(assert-equal
14+
"One for you, one for me."
15+
(two-fer:twofer nil)))
16+
17+
18+
(define-test
19+
a-name-given
20+
(assert-equal
21+
"One for Alice, one for me."
22+
(two-fer:twofer "Alice")))
23+
24+
25+
(define-test
26+
another-name-given
27+
(assert-equal
28+
"One for Bob, one for me."
29+
(two-fer:twofer "Bob")))
30+
31+
#-xlisp-test
32+
(let ((*print-errors* t)
33+
(*print-failures* t))
34+
(run-tests :all))

exercises/two-fer/two-fer.lisp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(in-package #:cl-user)
2+
(defpackage #:two-fer
3+
(:use #:cl)
4+
(:export #:twofer))
5+
(in-package #:two-fer)
6+
7+
(defun twofer (name))

0 commit comments

Comments
 (0)