Skip to content

Commit 5780447

Browse files
Add line-up exercise (#269)
1 parent 7d22aa3 commit 5780447

File tree

8 files changed

+213
-0
lines changed

8 files changed

+213
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,14 @@
527527
"prerequisites": [],
528528
"difficulty": 4
529529
},
530+
{
531+
"slug": "line-up",
532+
"name": "Line up",
533+
"uuid": "83de8377-61a5-4f8b-9cd2-644a60d5ea53",
534+
"practices": [],
535+
"prerequisites": [],
536+
"difficulty": 4
537+
},
530538
{
531539
"slug": "matching-brackets",
532540
"name": "Matching Brackets",
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.v"
8+
],
9+
"test": [
10+
"run_test.v"
11+
],
12+
"example": [
13+
".meta/example.v"
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module main
2+
3+
fn format(name string, number int) string {
4+
return '${name}, you are the ${number}${suffix(number)} customer we serve today. Thank you!'
5+
}
6+
7+
fn suffix(number int) string {
8+
last_two := number % 100
9+
if last_two % 10 == 1 && last_two != 11 {
10+
return 'st'
11+
}
12+
if last_two % 10 == 2 && last_two != 12 {
13+
return 'nd'
14+
}
15+
if last_two % 10 == 3 && last_two != 13 {
16+
return 'rd'
17+
}
18+
return 'th'
19+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This is an auto-generated file. Regular comments will be removed when this
2+
# file is regenerated. Regenerating will not touch any manually added keys,
3+
# so comments can be added in a "comment" key.
4+
5+
[7760d1b8-4864-4db4-953b-0fa7c047dbc0]
6+
description = "format smallest non-exceptional ordinal numeral 4"
7+
8+
[e8b7c715-6baa-4f7b-8fb3-2fa48044ab7a]
9+
description = "format greatest single digit non-exceptional ordinal numeral 9"
10+
11+
[f370aae9-7ae7-4247-90ce-e8ff8c6934df]
12+
description = "format non-exceptional ordinal numeral 5"
13+
14+
[37f10dea-42a2-49de-bb92-0b690b677908]
15+
description = "format non-exceptional ordinal numeral 6"
16+
17+
[d8dfb9a2-3a1f-4fee-9dae-01af3600054e]
18+
description = "format non-exceptional ordinal numeral 7"
19+
20+
[505ec372-1803-42b1-9377-6934890fd055]
21+
description = "format non-exceptional ordinal numeral 8"
22+
23+
[8267072d-be1f-4f70-b34a-76b7557a47b9]
24+
description = "format exceptional ordinal numeral 1"
25+
26+
[4d8753cb-0364-4b29-84b8-4374a4fa2e3f]
27+
description = "format exceptional ordinal numeral 2"
28+
29+
[8d44c223-3a7e-4f48-a0ca-78e67bf98aa7]
30+
description = "format exceptional ordinal numeral 3"
31+
32+
[6c4f6c88-b306-4f40-bc78-97cdd583c21a]
33+
description = "format smallest two digit non-exceptional ordinal numeral 10"
34+
35+
[e257a43f-d2b1-457a-97df-25f0923fc62a]
36+
description = "format non-exceptional ordinal numeral 11"
37+
38+
[bb1db695-4d64-457f-81b8-4f5a2107e3f4]
39+
description = "format non-exceptional ordinal numeral 12"
40+
41+
[60a3187c-9403-4835-97de-4f10ebfd63e2]
42+
description = "format non-exceptional ordinal numeral 13"
43+
44+
[2bdcebc5-c029-4874-b6cc-e9bec80d603a]
45+
description = "format exceptional ordinal numeral 21"
46+
47+
[74ee2317-0295-49d2-baf0-d56bcefa14e3]
48+
description = "format exceptional ordinal numeral 62"
49+
50+
[b37c332d-7f68-40e3-8503-e43cbd67a0c4]
51+
description = "format exceptional ordinal numeral 100"
52+
53+
[0375f250-ce92-4195-9555-00e28ccc4d99]
54+
description = "format exceptional ordinal numeral 101"
55+
56+
[0d8a4974-9a8a-45a4-aca7-a9fb473c9836]
57+
description = "format non-exceptional ordinal numeral 112"
58+
59+
[06b62efe-199e-4ce7-970d-4bf73945713f]
60+
description = "format exceptional ordinal numeral 123"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module main
2+
3+
fn format(name string, number int) string {
4+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module main
2+
3+
fn test_format_smallest_non_exceptional_ordinal_numeral_4() {
4+
assert format('Gianna', 4) == 'Gianna, you are the 4th customer we serve today. Thank you!'
5+
}
6+
7+
fn test_format_greatest_single_digit_non_exceptional_ordinal_numeral_9() {
8+
assert format('Maarten', 9) == 'Maarten, you are the 9th customer we serve today. Thank you!'
9+
}
10+
11+
fn test_format_non_exceptional_ordinal_numeral_5() {
12+
assert format('Petronila', 5) == 'Petronila, you are the 5th customer we serve today. Thank you!'
13+
}
14+
15+
fn test_format_non_exceptional_ordinal_numeral_6() {
16+
assert format('Attakullakulla', 6) == 'Attakullakulla, you are the 6th customer we serve today. Thank you!'
17+
}
18+
19+
fn test_format_non_exceptional_ordinal_numeral_7() {
20+
assert format('Kate', 7) == 'Kate, you are the 7th customer we serve today. Thank you!'
21+
}
22+
23+
fn test_format_non_exceptional_ordinal_numeral_8() {
24+
assert format('Maximiliano', 8) == 'Maximiliano, you are the 8th customer we serve today. Thank you!'
25+
}
26+
27+
fn test_format_exceptional_ordinal_numeral_1() {
28+
assert format('Mary', 1) == 'Mary, you are the 1st customer we serve today. Thank you!'
29+
}
30+
31+
fn test_format_exceptional_ordinal_numeral_2() {
32+
assert format('Haruto', 2) == 'Haruto, you are the 2nd customer we serve today. Thank you!'
33+
}
34+
35+
fn test_format_exceptional_ordinal_numeral_3() {
36+
assert format('Henriette', 3) == 'Henriette, you are the 3rd customer we serve today. Thank you!'
37+
}
38+
39+
fn test_format_smallest_two_digit_non_exceptional_ordinal_numeral_10() {
40+
assert format('Alvarez', 10) == 'Alvarez, you are the 10th customer we serve today. Thank you!'
41+
}
42+
43+
fn test_format_non_exceptional_ordinal_numeral_11() {
44+
assert format('Jacqueline', 11) == 'Jacqueline, you are the 11th customer we serve today. Thank you!'
45+
}
46+
47+
fn test_format_non_exceptional_ordinal_numeral_12() {
48+
assert format('Juan', 12) == 'Juan, you are the 12th customer we serve today. Thank you!'
49+
}
50+
51+
fn test_format_non_exceptional_ordinal_numeral_13() {
52+
assert format('Patricia', 13) == 'Patricia, you are the 13th customer we serve today. Thank you!'
53+
}
54+
55+
fn test_format_exceptional_ordinal_numeral_21() {
56+
assert format('Washi', 21) == 'Washi, you are the 21st customer we serve today. Thank you!'
57+
}
58+
59+
fn test_format_exceptional_ordinal_numeral_62() {
60+
assert format('Nayra', 62) == 'Nayra, you are the 62nd customer we serve today. Thank you!'
61+
}
62+
63+
fn test_format_exceptional_ordinal_numeral_100() {
64+
assert format('John', 100) == 'John, you are the 100th customer we serve today. Thank you!'
65+
}
66+
67+
fn test_format_exceptional_ordinal_numeral_101() {
68+
assert format('Zeinab', 101) == 'Zeinab, you are the 101st customer we serve today. Thank you!'
69+
}
70+
71+
fn test_format_non_exceptional_ordinal_numeral_112() {
72+
assert format('Knud', 112) == 'Knud, you are the 112th customer we serve today. Thank you!'
73+
}
74+
75+
fn test_format_exceptional_ordinal_numeral_123() {
76+
assert format('Yma', 123) == 'Yma, you are the 123rd customer we serve today. Thank you!'
77+
}

0 commit comments

Comments
 (0)