Skip to content

Commit b0239ea

Browse files
Add line-up exercise (#612)
1 parent 4c08ac0 commit b0239ea

12 files changed

Lines changed: 299 additions & 45 deletions

File tree

bin/add-practice-exercise

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fi
6767
./bin/fetch-configlet
6868
./bin/configlet create --practice-exercise "${slug}" --author "${author}" --difficulty "${difficulty}"
6969

70-
filter='.exercises.practice = (.exercises.practice | sort_by(.difficulty, .slug))'
70+
filter='.exercises.practice = (.exercises.practice | sort_by(.difficulty, (.name|ascii_upcase))'
7171
jq "${filter}" config.json > config.sorted && mv config.sorted config.json
7272

7373
exercise_dir="exercises/practice/${slug}"

config.json

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@
458458
"strings"
459459
]
460460
},
461+
{
462+
"slug": "line-up",
463+
"name": "Line Up",
464+
"uuid": "2a4e105e-5545-4baf-aba5-75cbc5aee498",
465+
"practices": [],
466+
"prerequisites": [],
467+
"difficulty": 3
468+
},
461469
{
462470
"slug": "matrix",
463471
"name": "Matrix",
@@ -567,28 +575,28 @@
567575
"difficulty": 3
568576
},
569577
{
570-
"slug": "rna-transcription",
571-
"name": "RNA Transcription",
572-
"uuid": "5029a8ed-3766-4632-bdab-964ca4a06e34",
578+
"slug": "reverse-string",
579+
"name": "Reverse String",
580+
"uuid": "2d443a8f-65de-496e-9527-8a54a840ba69",
573581
"practices": [],
574582
"prerequisites": [],
575583
"difficulty": 3,
576584
"topics": [
577-
"control_flow_loops",
578-
"strings",
579-
"transforming"
585+
"arrays",
586+
"strings"
580587
]
581588
},
582589
{
583-
"slug": "reverse-string",
584-
"name": "Reverse String",
585-
"uuid": "2d443a8f-65de-496e-9527-8a54a840ba69",
590+
"slug": "rna-transcription",
591+
"name": "RNA Transcription",
592+
"uuid": "5029a8ed-3766-4632-bdab-964ca4a06e34",
586593
"practices": [],
587594
"prerequisites": [],
588595
"difficulty": 3,
589596
"topics": [
590-
"arrays",
591-
"strings"
597+
"control_flow_loops",
598+
"strings",
599+
"transforming"
592600
]
593601
},
594602
{
@@ -776,6 +784,14 @@
776784
"text_formatting"
777785
]
778786
},
787+
{
788+
"slug": "dominoes",
789+
"name": "Dominoes",
790+
"uuid": "0ea6977c-5032-40ab-bd67-be23e052c69f",
791+
"practices": [],
792+
"prerequisites": [],
793+
"difficulty": 4
794+
},
779795
{
780796
"slug": "grade-school",
781797
"name": "Grade School",
@@ -988,14 +1004,6 @@
9881004
"prerequisites": [],
9891005
"difficulty": 4
9901006
},
991-
{
992-
"slug": "dominoes",
993-
"name": "Dominoes",
994-
"uuid": "0ea6977c-5032-40ab-bd67-be23e052c69f",
995-
"practices": [],
996-
"prerequisites": [],
997-
"difficulty": 4
998-
},
9991007
{
10001008
"slug": "affine-cipher",
10011009
"name": "Affine Cipher",
@@ -1113,6 +1121,14 @@
11131121
"strings"
11141122
]
11151123
},
1124+
{
1125+
"slug": "palindrome-products",
1126+
"name": "Palindrome Products",
1127+
"uuid": "928d3505-7780-4d2d-8fd8-7c8f0aac4033",
1128+
"practices": [],
1129+
"prerequisites": [],
1130+
"difficulty": 5
1131+
},
11161132
{
11171133
"slug": "pascals-triangle",
11181134
"name": "Pascal's Triangle",
@@ -1189,14 +1205,6 @@
11891205
"text_parsing"
11901206
]
11911207
},
1192-
{
1193-
"slug": "palindrome-products",
1194-
"name": "Palindrome Products",
1195-
"uuid": "928d3505-7780-4d2d-8fd8-7c8f0aac4033",
1196-
"practices": [],
1197-
"prerequisites": [],
1198-
"difficulty": 5
1199-
},
12001208
{
12011209
"slug": "anagram",
12021210
"name": "Anagram",
@@ -1219,6 +1227,14 @@
12191227
"prerequisites": [],
12201228
"difficulty": 6
12211229
},
1230+
{
1231+
"slug": "complex-numbers",
1232+
"name": "Complex Numbers",
1233+
"uuid": "ed6b5073-e3b1-4787-8551-ffffa9e7313d",
1234+
"practices": [],
1235+
"prerequisites": [],
1236+
"difficulty": 6
1237+
},
12221238
{
12231239
"slug": "custom-set",
12241240
"name": "Custom Set",
@@ -1288,17 +1304,9 @@
12881304
]
12891305
},
12901306
{
1291-
"slug": "complex-numbers",
1292-
"name": "Complex Numbers",
1293-
"uuid": "ed6b5073-e3b1-4787-8551-ffffa9e7313d",
1294-
"practices": [],
1295-
"prerequisites": [],
1296-
"difficulty": 6
1297-
},
1298-
{
1299-
"slug": "minesweeper",
1300-
"name": "Minesweeper",
1301-
"uuid": "fcb9cc16-7690-4ee6-a373-c8476063ec57",
1307+
"slug": "flower-field",
1308+
"name": "Flower Field",
1309+
"uuid": "7915cf5b-bd42-45aa-abd7-21dfb0059169",
13021310
"practices": [],
13031311
"prerequisites": [],
13041312
"difficulty": 7,
@@ -1308,16 +1316,16 @@
13081316
"control_flow_loops",
13091317
"exception_handling",
13101318
"strings"
1311-
],
1312-
"status": "deprecated"
1319+
]
13131320
},
13141321
{
1315-
"slug": "flower-field",
1316-
"name": "Flower Field",
1317-
"uuid": "7915cf5b-bd42-45aa-abd7-21dfb0059169",
1322+
"slug": "minesweeper",
1323+
"name": "Minesweeper",
1324+
"uuid": "fcb9cc16-7690-4ee6-a373-c8476063ec57",
13181325
"practices": [],
13191326
"prerequisites": [],
13201327
"difficulty": 7,
1328+
"status": "deprecated",
13211329
"topics": [
13221330
"arrays",
13231331
"control_flow_if_else_statements",

exercises/practice/flower-field/.meta/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"authors": [
33
"ryanplusplus"
44
],
5-
"contributors": [],
65
"files": {
76
"solution": [
87
"flower-field.lua"

exercises/practice/line-up/.busted

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
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.lua"
8+
],
9+
"test": [
10+
"line-up_spec.lua"
11+
],
12+
"example": [
13+
".meta/example.lua"
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+
return {
2+
format = function(name, number)
3+
local suffix = 'th'
4+
if number // 10 % 10 ~= 1 then
5+
local last = number % 10
6+
if last == 1 then
7+
suffix = 'st'
8+
end
9+
if last == 2 then
10+
suffix = 'nd'
11+
end
12+
if last == 3 then
13+
suffix = 'rd'
14+
end
15+
end
16+
return string.format('%s, you are the %d%s customer we serve today. Thank you!', name, number, suffix)
17+
end
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
return {
2+
module_name = 'line_up',
3+
4+
generate_test = function(case)
5+
local template = [[
6+
local expected = '%s'
7+
assert.are.same(expected, line_up.format('%s', %d))]]
8+
return template:format(case.expected, case.input.name, case.input.number)
9+
end
10+
}
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"

0 commit comments

Comments
 (0)