Skip to content

Commit b9ed62b

Browse files
authored
[New Exercise]: Line Up (#422)
Add exercise `Line Up`
1 parent 83fd299 commit b9ed62b

8 files changed

Lines changed: 319 additions & 0 deletions

File tree

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@
614614
"practices": [],
615615
"prerequisites": [],
616616
"difficulty": 2
617+
},
618+
{
619+
"slug": "line-up",
620+
"name": "Line Up",
621+
"uuid": "35d96adf-0fc2-4442-9299-76d880a70b3c",
622+
"practices": [],
623+
"prerequisites": [],
624+
"difficulty": 2
617625
},
618626
{
619627
"slug": "error-handling",
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Function Get-LineUp() {
2+
<#
3+
.SYNOPSIS
4+
Produce a greeting for customer in a line.
5+
6+
.DESCRIPTION
7+
Given a name and a number, your task is to produce a sentence using that name and that number as an ordinal numeral.
8+
9+
.PARAMETER Name
10+
String represents name of the customer.
11+
12+
.PARAMETER Number
13+
Integer represents the order of the customer in line. (1 to 999)
14+
15+
.EXAMPLE
16+
Get-LineUp -Name "Exercism" -Number 1
17+
Returns: "Exercism, you are the 1st customer we serve today. Thank you!"
18+
#>
19+
[CmdletBinding()]
20+
Param(
21+
[string]$Name,
22+
[int]$Number
23+
)
24+
25+
$tens = $Number % 100
26+
$ones = $Number % 10
27+
28+
$ordinal = switch ($true) {
29+
{ $tens -ge 11 -and $tens -le 13 } { 'th'; break }
30+
{ $ones -eq 1 } {'st'}
31+
{ $ones -eq 2 } {'nd'}
32+
{ $ones -eq 3 } {'rd'}
33+
default { 'th' }
34+
}
35+
"$Name, you are the $Number$ordinal customer we serve today. Thank you!"
36+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"glaxxie"
4+
],
5+
"files": {
6+
"solution": [
7+
"LineUp.ps1"
8+
],
9+
"test": [
10+
"LineUp.tests.ps1"
11+
],
12+
"example": [
13+
".meta/LineUp.example.ps1"
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: 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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Function Get-LineUp() {
2+
<#
3+
.SYNOPSIS
4+
Produce a greeting for customer in a line.
5+
6+
.DESCRIPTION
7+
Given a name and a number, your task is to produce a sentence using that name and that number as an ordinal numeral.
8+
9+
.PARAMETER Name
10+
String represents name of the customer.
11+
12+
.PARAMETER Number
13+
Integer represents the order of the customer in line. (1 to 999)
14+
15+
.EXAMPLE
16+
Get-LineUp -Name "Exercism" -Number 1
17+
Returns: "Exercism, you are the 1st customer we serve today. Thank you!"
18+
#>
19+
[CmdletBinding()]
20+
Param(
21+
[string]$Name,
22+
[int]$Number
23+
)
24+
Throw "Please implement this function"
25+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
BeforeAll {
2+
. "./LineUp.ps1"
3+
}
4+
5+
Describe "LineUp test cases" {
6+
It "format smallest non-exceptional ordinal numeral 4" {
7+
$got = Get-LineUp -Name "Gianna" -Number 4
8+
$expect = "Gianna, you are the 4th customer we serve today. Thank you!"
9+
10+
$got | Should -BeExactly $expect
11+
}
12+
13+
It "format greatest single digit non-exceptional ordinal numeral 9" {
14+
$got = Get-LineUp -Name "Maarten" -Number 9
15+
$expect = "Maarten, you are the 9th customer we serve today. Thank you!"
16+
17+
$got | Should -BeExactly $expect
18+
}
19+
20+
It "format non-exceptional ordinal numeral 5" {
21+
$got = Get-LineUp -Name "Petronila" -Number 5
22+
$expect = "Petronila, you are the 5th customer we serve today. Thank you!"
23+
24+
$got | Should -BeExactly $expect
25+
}
26+
27+
It "format non-exceptional ordinal numeral 6" {
28+
$got = Get-LineUp -Name "Attakullakulla" -Number 6
29+
$expect = "Attakullakulla, you are the 6th customer we serve today. Thank you!"
30+
31+
$got | Should -BeExactly $expect
32+
}
33+
34+
It "format non-exceptional ordinal numeral 7" {
35+
$got = Get-LineUp -Name "Kate" -Number 7
36+
$expect = "Kate, you are the 7th customer we serve today. Thank you!"
37+
38+
$got | Should -BeExactly $expect
39+
}
40+
41+
It "format non-exceptional ordinal numeral 8" {
42+
$got = Get-LineUp -Name "Maximiliano" -Number 8
43+
$expect = "Maximiliano, you are the 8th customer we serve today. Thank you!"
44+
45+
$got | Should -BeExactly $expect
46+
}
47+
48+
It "format exceptional ordinal numeral 1" {
49+
$got = Get-LineUp -Name "Mary" -Number 1
50+
$expect = "Mary, you are the 1st customer we serve today. Thank you!"
51+
52+
$got | Should -BeExactly $expect
53+
}
54+
55+
It "format exceptional ordinal numeral 2" {
56+
$got = Get-LineUp -Name "Haruto" -Number 2
57+
$expect = "Haruto, you are the 2nd customer we serve today. Thank you!"
58+
59+
$got | Should -BeExactly $expect
60+
}
61+
62+
It "format exceptional ordinal numeral 3" {
63+
$got = Get-LineUp -Name "Henriette" -Number 3
64+
$expect = "Henriette, you are the 3rd customer we serve today. Thank you!"
65+
66+
$got | Should -BeExactly $expect
67+
}
68+
69+
It "format smallest two digit non-exceptional ordinal numeral 10" {
70+
$got = Get-LineUp -Name "Alvarez" -Number 10
71+
$expect = "Alvarez, you are the 10th customer we serve today. Thank you!"
72+
73+
$got | Should -BeExactly $expect
74+
}
75+
76+
It "format non-exceptional ordinal numeral 11" {
77+
$got = Get-LineUp -Name "Jacqueline" -Number 11
78+
$expect = "Jacqueline, you are the 11th customer we serve today. Thank you!"
79+
80+
$got | Should -BeExactly $expect
81+
}
82+
83+
It "format non-exceptional ordinal numeral 12" {
84+
$got = Get-LineUp -Name "Juan" -Number 12
85+
$expect = "Juan, you are the 12th customer we serve today. Thank you!"
86+
87+
$got | Should -BeExactly $expect
88+
}
89+
90+
It "format non-exceptional ordinal numeral 13" {
91+
$got = Get-LineUp -Name "Patricia" -Number 13
92+
$expect = "Patricia, you are the 13th customer we serve today. Thank you!"
93+
94+
$got | Should -BeExactly $expect
95+
}
96+
97+
It "format exceptional ordinal numeral 21" {
98+
$got = Get-LineUp -Name "Washi" -Number 21
99+
$expect = "Washi, you are the 21st customer we serve today. Thank you!"
100+
101+
$got | Should -BeExactly $expect
102+
}
103+
104+
It "format exceptional ordinal numeral 62" {
105+
$got = Get-LineUp -Name "Nayra" -Number 62
106+
$expect = "Nayra, you are the 62nd customer we serve today. Thank you!"
107+
108+
$got | Should -BeExactly $expect
109+
}
110+
111+
It "format exceptional ordinal numeral 100" {
112+
$got = Get-LineUp -Name "John" -Number 100
113+
$expect = "John, you are the 100th customer we serve today. Thank you!"
114+
115+
$got | Should -BeExactly $expect
116+
}
117+
118+
It "format exceptional ordinal numeral 101" {
119+
$got = Get-LineUp -Name "Zeinab" -Number 101
120+
$expect = "Zeinab, you are the 101st customer we serve today. Thank you!"
121+
122+
$got | Should -BeExactly $expect
123+
}
124+
125+
It "format non-exceptional ordinal numeral 112" {
126+
$got = Get-LineUp -Name "Knud" -Number 112
127+
$expect = "Knud, you are the 112th customer we serve today. Thank you!"
128+
129+
$got | Should -BeExactly $expect
130+
}
131+
132+
It "format exceptional ordinal numeral 123" {
133+
$got = Get-LineUp -Name "Yma" -Number 123
134+
$expect = "Yma, you are the 123rd customer we serve today. Thank you!"
135+
136+
$got | Should -BeExactly $expect
137+
}
138+
}

0 commit comments

Comments
 (0)