Skip to content

Commit 5a22602

Browse files
authored
Add line-up (#362)
1 parent 8f48989 commit 5a22602

File tree

8 files changed

+263
-0
lines changed

8 files changed

+263
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@
271271
"logic"
272272
]
273273
},
274+
{
275+
"slug": "line-up",
276+
"name": "Line Up",
277+
"uuid": "759c4de8-cfb4-4846-af7e-468c40601f7c",
278+
"practices": [],
279+
"prerequisites": [],
280+
"difficulty": 2
281+
},
274282
{
275283
"slug": "luhn",
276284
"name": "Luhn",
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+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"line_up.vim"
8+
],
9+
"test": [
10+
"line_up.vader"
11+
],
12+
"example": [
13+
".meta/example.vim"
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function! Format(name, number) abort
2+
let l:suffix = s:Suffix(a:number)
3+
return printf('%s, you are the %d%s customer we serve today. Thank you!', a:name, a:number, l:suffix)
4+
endfunction
5+
6+
function! s:Suffix(number) abort
7+
let l:mod10 = a:number % 10
8+
let l:mod100 = a:number % 100
9+
10+
if l:mod10 == 1 && l:mod100 != 11
11+
return 'st'
12+
elseif l:mod10 == 2 && l:mod100 != 12
13+
return 'nd'
14+
elseif l:mod10 == 3 && l:mod100 != 13
15+
return 'rd'
16+
endif
17+
return 'th'
18+
endfunction
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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
Execute (format smallest non-exceptional ordinal numeral 4):
3+
let g:name = "Gianna"
4+
let g:number = 4
5+
let g:expected = "Gianna, you are the 4th customer we serve today. Thank you!"
6+
AssertEqual g:expected, Format(g:name, g:number)
7+
8+
Execute (format greatest single digit non-exceptional ordinal numeral 9):
9+
let g:name = "Maarten"
10+
let g:number = 9
11+
let g:expected = "Maarten, you are the 9th customer we serve today. Thank you!"
12+
AssertEqual g:expected, Format(g:name, g:number)
13+
14+
Execute (format non-exceptional ordinal numeral 5):
15+
let g:name = "Petronila"
16+
let g:number = 5
17+
let g:expected = "Petronila, you are the 5th customer we serve today. Thank you!"
18+
AssertEqual g:expected, Format(g:name, g:number)
19+
20+
Execute (format non-exceptional ordinal numeral 6):
21+
let g:name = "Attakullakulla"
22+
let g:number = 6
23+
let g:expected = "Attakullakulla, you are the 6th customer we serve today. Thank you!"
24+
AssertEqual g:expected, Format(g:name, g:number)
25+
26+
Execute (format non-exceptional ordinal numeral 7):
27+
let g:name = "Kate"
28+
let g:number = 7
29+
let g:expected = "Kate, you are the 7th customer we serve today. Thank you!"
30+
AssertEqual g:expected, Format(g:name, g:number)
31+
32+
Execute (format non-exceptional ordinal numeral 8):
33+
let g:name = "Maximiliano"
34+
let g:number = 8
35+
let g:expected = "Maximiliano, you are the 8th customer we serve today. Thank you!"
36+
AssertEqual g:expected, Format(g:name, g:number)
37+
38+
Execute (format exceptional ordinal numeral 1):
39+
let g:name = "Mary"
40+
let g:number = 1
41+
let g:expected = "Mary, you are the 1st customer we serve today. Thank you!"
42+
AssertEqual g:expected, Format(g:name, g:number)
43+
44+
Execute (format exceptional ordinal numeral 2):
45+
let g:name = "Haruto"
46+
let g:number = 2
47+
let g:expected = "Haruto, you are the 2nd customer we serve today. Thank you!"
48+
AssertEqual g:expected, Format(g:name, g:number)
49+
50+
Execute (format exceptional ordinal numeral 3):
51+
let g:name = "Henriette"
52+
let g:number = 3
53+
let g:expected = "Henriette, you are the 3rd customer we serve today. Thank you!"
54+
AssertEqual g:expected, Format(g:name, g:number)
55+
56+
Execute (format smallest two digit non-exceptional ordinal numeral 10):
57+
let g:name = "Alvarez"
58+
let g:number = 10
59+
let g:expected = "Alvarez, you are the 10th customer we serve today. Thank you!"
60+
AssertEqual g:expected, Format(g:name, g:number)
61+
62+
Execute (format non-exceptional ordinal numeral 11):
63+
let g:name = "Jacqueline"
64+
let g:number = 11
65+
let g:expected = "Jacqueline, you are the 11th customer we serve today. Thank you!"
66+
AssertEqual g:expected, Format(g:name, g:number)
67+
68+
Execute (format non-exceptional ordinal numeral 12):
69+
let g:name = "Juan"
70+
let g:number = 12
71+
let g:expected = "Juan, you are the 12th customer we serve today. Thank you!"
72+
AssertEqual g:expected, Format(g:name, g:number)
73+
74+
Execute (format non-exceptional ordinal numeral 13):
75+
let g:name = "Patricia"
76+
let g:number = 13
77+
let g:expected = "Patricia, you are the 13th customer we serve today. Thank you!"
78+
AssertEqual g:expected, Format(g:name, g:number)
79+
80+
Execute (format exceptional ordinal numeral 21):
81+
let g:name = "Washi"
82+
let g:number = 21
83+
let g:expected = "Washi, you are the 21st customer we serve today. Thank you!"
84+
AssertEqual g:expected, Format(g:name, g:number)
85+
86+
Execute (format exceptional ordinal numeral 62):
87+
let g:name = "Nayra"
88+
let g:number = 62
89+
let g:expected = "Nayra, you are the 62nd customer we serve today. Thank you!"
90+
AssertEqual g:expected, Format(g:name, g:number)
91+
92+
Execute (format exceptional ordinal numeral 100):
93+
let g:name = "John"
94+
let g:number = 100
95+
let g:expected = "John, you are the 100th customer we serve today. Thank you!"
96+
AssertEqual g:expected, Format(g:name, g:number)
97+
98+
Execute (format exceptional ordinal numeral 101):
99+
let g:name = "Zeinab"
100+
let g:number = 101
101+
let g:expected = "Zeinab, you are the 101st customer we serve today. Thank you!"
102+
AssertEqual g:expected, Format(g:name, g:number)
103+
104+
Execute (format non-exceptional ordinal numeral 112):
105+
let g:name = "Knud"
106+
let g:number = 112
107+
let g:expected = "Knud, you are the 112th customer we serve today. Thank you!"
108+
AssertEqual g:expected, Format(g:name, g:number)
109+
110+
Execute (format exceptional ordinal numeral 123):
111+
let g:name = "Yma"
112+
let g:number = 123
113+
let g:expected = "Yma, you are the 123rd customer we serve today. Thank you!"
114+
AssertEqual g:expected, Format(g:name, g:number)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"
2+
" Given a customer ame and a ticket number, return a formatted ticket message.
3+
"
4+
" Example:
5+
"
6+
" :echo Format('Maarten', 9)
7+
" Maarten, you are the 9th customer we serve today. Thank you!
8+
"
9+
function! Format(name, number) abort
10+
" your code goes here
11+
endfunction

0 commit comments

Comments
 (0)