Skip to content

Commit 4f3ca51

Browse files
Add line-up exercise (#503)
1 parent 96b16b4 commit 4f3ca51

File tree

8 files changed

+273
-2
lines changed

8 files changed

+273
-2
lines changed

config.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@
582582
"strings"
583583
]
584584
},
585+
{
586+
"slug": "line-up",
587+
"name": "Line Up",
588+
"uuid": "cb7d3d70-185d-47cb-b8b7-a0f6ce1c0cf5",
589+
"practices": [],
590+
"prerequisites": [],
591+
"difficulty": 4
592+
},
585593
{
586594
"slug": "matching-brackets",
587595
"name": "Matching Brackets",
@@ -818,10 +826,10 @@
818826
"practices": [],
819827
"prerequisites": [],
820828
"difficulty": 5,
829+
"status": "deprecated",
821830
"topics": [
822831
"control_flow_loops"
823-
],
824-
"status": "deprecated"
832+
]
825833
},
826834
{
827835
"slug": "nucleotide-count",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Instructions
2+
3+
Given a name and a number, your task is to produce a sentence using that name and that number as an [ordinal numeral][ordinal-numeral].
4+
Yaʻqūb expects to use numbers from 1 up to 999.
5+
6+
Rules:
7+
8+
- Numbers ending in 1 (except for 11) → `"st"`
9+
- Numbers ending in 2 (except for 12) → `"nd"`
10+
- Numbers ending in 3 (except for 13) → `"rd"`
11+
- All other numbers → `"th"`
12+
13+
Examples:
14+
15+
- `"Mary", 1``"Mary, you are the 1st customer we serve today. Thank you!"`
16+
- `"John", 12``"John, you are the 12th customer we serve today. Thank you!"`
17+
- `"Dahir", 162``"Dahir, you are the 162nd customer we serve today. Thank you!"`
18+
19+
[ordinal-numeral]: https://en.wikipedia.org/wiki/Ordinal_numeral
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
Your friend Yaʻqūb works the counter at a deli in town, slicing, weighing, and wrapping orders for a line of hungry customers that gets longer every day.
4+
Waiting customers are starting to lose track of who is next, so he wants numbered tickets they can use to track the order in which they arrive.
5+
6+
To make the customers feel special, he does not want the ticket to have only a number on it.
7+
They shall get a proper English sentence with their name and number on it.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"line-up.el"
8+
],
9+
"test": [
10+
"line-up-test.el"
11+
],
12+
"example": [
13+
".meta/example.el"
14+
]
15+
},
16+
"blurb": "Help lining up customers at Yaʻqūb's Deli.",
17+
"source": "mk-mxp, based on previous work from Exercism contributors codedge and neenjaw",
18+
"source_url": "https://forum.exercism.org/t/new-exercise-ordinal-numbers/19147"
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;;; line-up.el --- Line Up (exercism) -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
5+
;;; Code:
6+
7+
8+
(defun suffix (number)
9+
(let ((units (mod number 10))
10+
(tens (mod (/ number 10) 10)))
11+
(cond ((= tens 1) "th")
12+
((= units 1) "st")
13+
((= units 2) "nd")
14+
((= units 3) "rd")
15+
(t "th"))))
16+
17+
18+
(defun ticket (name number)
19+
(concat
20+
name
21+
", you are the "
22+
(number-to-string number)
23+
(suffix number)
24+
" customer we serve today. Thank you!"))
25+
26+
27+
(provide 'line-up)
28+
;;; line-up.el ends here
29+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[7760d1b8-4864-4db4-953b-0fa7c047dbc0]
13+
description = "format smallest non-exceptional ordinal numeral 4"
14+
15+
[e8b7c715-6baa-4f7b-8fb3-2fa48044ab7a]
16+
description = "format greatest single digit non-exceptional ordinal numeral 9"
17+
18+
[f370aae9-7ae7-4247-90ce-e8ff8c6934df]
19+
description = "format non-exceptional ordinal numeral 5"
20+
21+
[37f10dea-42a2-49de-bb92-0b690b677908]
22+
description = "format non-exceptional ordinal numeral 6"
23+
24+
[d8dfb9a2-3a1f-4fee-9dae-01af3600054e]
25+
description = "format non-exceptional ordinal numeral 7"
26+
27+
[505ec372-1803-42b1-9377-6934890fd055]
28+
description = "format non-exceptional ordinal numeral 8"
29+
30+
[8267072d-be1f-4f70-b34a-76b7557a47b9]
31+
description = "format exceptional ordinal numeral 1"
32+
33+
[4d8753cb-0364-4b29-84b8-4374a4fa2e3f]
34+
description = "format exceptional ordinal numeral 2"
35+
36+
[8d44c223-3a7e-4f48-a0ca-78e67bf98aa7]
37+
description = "format exceptional ordinal numeral 3"
38+
39+
[6c4f6c88-b306-4f40-bc78-97cdd583c21a]
40+
description = "format smallest two digit non-exceptional ordinal numeral 10"
41+
42+
[e257a43f-d2b1-457a-97df-25f0923fc62a]
43+
description = "format non-exceptional ordinal numeral 11"
44+
45+
[bb1db695-4d64-457f-81b8-4f5a2107e3f4]
46+
description = "format non-exceptional ordinal numeral 12"
47+
48+
[60a3187c-9403-4835-97de-4f10ebfd63e2]
49+
description = "format non-exceptional ordinal numeral 13"
50+
51+
[2bdcebc5-c029-4874-b6cc-e9bec80d603a]
52+
description = "format exceptional ordinal numeral 21"
53+
54+
[74ee2317-0295-49d2-baf0-d56bcefa14e3]
55+
description = "format exceptional ordinal numeral 62"
56+
57+
[b37c332d-7f68-40e3-8503-e43cbd67a0c4]
58+
description = "format exceptional ordinal numeral 100"
59+
60+
[0375f250-ce92-4195-9555-00e28ccc4d99]
61+
description = "format exceptional ordinal numeral 101"
62+
63+
[0d8a4974-9a8a-45a4-aca7-a9fb473c9836]
64+
description = "format non-exceptional ordinal numeral 112"
65+
66+
[06b62efe-199e-4ce7-970d-4bf73945713f]
67+
description = "format exceptional ordinal numeral 123"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
;;; line-up-test.el --- Line Up (exercism) -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
5+
;;; Code:
6+
7+
8+
(load-file "line-up.el")
9+
(declare-function ticket "line-up.el" (name number))
10+
11+
12+
(ert-deftest format-smallest-non-exceptional-ordinal-numeral-4 ()
13+
(should (string= "Gianna, you are the 4th customer we serve today. Thank you!"
14+
(ticket "Gianna" 4))))
15+
16+
17+
(ert-deftest format-greatest-single-digit-non-exceptional-ordinal-numeral-9 ()
18+
(should (string= "Maarten, you are the 9th customer we serve today. Thank you!"
19+
(ticket "Maarten" 9))))
20+
21+
22+
(ert-deftest format-non-exceptional-ordinal-numeral-5 ()
23+
(should (string= "Petronila, you are the 5th customer we serve today. Thank you!"
24+
(ticket "Petronila" 5))))
25+
26+
27+
(ert-deftest format-non-exceptional-ordinal-numeral-6 ()
28+
(should (string= "Attakullakulla, you are the 6th customer we serve today. Thank you!"
29+
(ticket "Attakullakulla" 6))))
30+
31+
32+
(ert-deftest format-non-exceptional-ordinal-numeral-7 ()
33+
(should (string= "Kate, you are the 7th customer we serve today. Thank you!"
34+
(ticket "Kate" 7))))
35+
36+
37+
(ert-deftest format-non-exceptional-ordinal-numeral-8 ()
38+
(should (string= "Maximiliano, you are the 8th customer we serve today. Thank you!"
39+
(ticket "Maximiliano" 8))))
40+
41+
42+
(ert-deftest format-exceptional-ordinal-numeral-1 ()
43+
(should (string= "Mary, you are the 1st customer we serve today. Thank you!"
44+
(ticket "Mary" 1))))
45+
46+
47+
(ert-deftest format-exceptional-ordinal-numeral-2 ()
48+
(should (string= "Haruto, you are the 2nd customer we serve today. Thank you!"
49+
(ticket "Haruto" 2))))
50+
51+
52+
(ert-deftest format-exceptional-ordinal-numeral-3 ()
53+
(should (string= "Henriette, you are the 3rd customer we serve today. Thank you!"
54+
(ticket "Henriette" 3))))
55+
56+
57+
(ert-deftest format-smallest-two-digit-non-exceptional-ordinal-numeral-10 ()
58+
(should (string= "Alvarez, you are the 10th customer we serve today. Thank you!"
59+
(ticket "Alvarez" 10))))
60+
61+
62+
(ert-deftest format-non-exceptional-ordinal-numeral-11 ()
63+
(should (string= "Jacqueline, you are the 11th customer we serve today. Thank you!"
64+
(ticket "Jacqueline" 11))))
65+
66+
67+
(ert-deftest format-non-exceptional-ordinal-numeral-12 ()
68+
(should (string= "Juan, you are the 12th customer we serve today. Thank you!"
69+
(ticket "Juan" 12))))
70+
71+
72+
(ert-deftest format-non-exceptional-ordinal-numeral-13 ()
73+
(should (string= "Patricia, you are the 13th customer we serve today. Thank you!"
74+
(ticket "Patricia" 13))))
75+
76+
77+
(ert-deftest format-exceptional-ordinal-numeral-21 ()
78+
(should (string= "Washi, you are the 21st customer we serve today. Thank you!"
79+
(ticket "Washi" 21))))
80+
81+
82+
(ert-deftest format-exceptional-ordinal-numeral-62 ()
83+
(should (string= "Nayra, you are the 62nd customer we serve today. Thank you!"
84+
(ticket "Nayra" 62))))
85+
86+
87+
(ert-deftest format-exceptional-ordinal-numeral-100 ()
88+
(should (string= "John, you are the 100th customer we serve today. Thank you!"
89+
(ticket "John" 100))))
90+
91+
92+
(ert-deftest format-exceptional-ordinal-numeral-101 ()
93+
(should (string= "Zeinab, you are the 101st customer we serve today. Thank you!"
94+
(ticket "Zeinab" 101))))
95+
96+
97+
(ert-deftest format-non-exceptional-ordinal-numeral-112 ()
98+
(should (string= "Knud, you are the 112th customer we serve today. Thank you!"
99+
(ticket "Knud" 112))))
100+
101+
102+
(ert-deftest format-exceptional-ordinal-numeral-123 ()
103+
(should (string= "Yma, you are the 123rd customer we serve today. Thank you!"
104+
(ticket "Yma" 123))))
105+
106+
107+
(provide 'line-up-test)
108+
;;; line-up-test.el ends here
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
;;; line-up.el --- Line Up (exercism) -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
5+
;;; Code:
6+
7+
8+
(defun ticket (name number)
9+
(error "Delete this S-Expression and write your own implementation"))
10+
11+
12+
(provide 'line-up)
13+
;;; line-up.el ends here
14+

0 commit comments

Comments
 (0)