Skip to content

Commit b1c62d0

Browse files
authored
Add new exercise line-up (#931)
1 parent 98271a4 commit b1c62d0

9 files changed

Lines changed: 396 additions & 1 deletion

File tree

bin/auto-sync.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ kindergarten-garden
4040
knapsack
4141
largest-series-product
4242
leap
43-
list-ops
43+
line-up
4444
linked-list
45+
list-ops
4546
luhn
4647
matching-brackets
4748
meetup

config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@
169169
"prerequisites": [],
170170
"difficulty": 1
171171
},
172+
{
173+
"slug": "line-up",
174+
"name": "Line up",
175+
"uuid": "6016009e-9012-447a-87b7-d33ea01492d9",
176+
"practices": [],
177+
"prerequisites": [],
178+
"difficulty": 2
179+
},
172180
{
173181
"slug": "hamming",
174182
"name": "Hamming",
@@ -1120,6 +1128,7 @@
11201128
"practices": [],
11211129
"prerequisites": [],
11221130
"difficulty": 2,
1131+
"status": "deprecated",
11231132
"topics": [
11241133
"strings",
11251134
"conditionals"
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"authors": [
3+
"codedge",
4+
"neenjaw",
5+
"mk-mxp"
6+
],
7+
"files": {
8+
"solution": [
9+
"LineUp.php"
10+
],
11+
"test": [
12+
"LineUpTest.php"
13+
],
14+
"example": [
15+
".meta/example.php"
16+
]
17+
},
18+
"blurb": "Help lining up customers at Yaʻqūb's Deli.",
19+
"source": "mk-mxp, based on previous work from Exercism contributors codedge and neenjaw",
20+
"source_url": "https://forum.exercism.org/t/new-exercise-ordinal-numbers/19147"
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
function format(string $name, int $number): string
6+
{
7+
return $name
8+
. ', you are the '
9+
. toOrdinal($number)
10+
. ' customer we serve today. Thank you!'
11+
;
12+
}
13+
14+
function toOrdinal(int $number): string
15+
{
16+
if (0 === $number) {
17+
return '0';
18+
}
19+
20+
$ending = 'th';
21+
22+
if (!in_array(($number % 100), [11, 12, 13])) {
23+
switch ($number % 10) {
24+
case 1:
25+
$ending = 'st';
26+
break;
27+
case 2:
28+
$ending = 'nd';
29+
break;
30+
case 3:
31+
$ending = 'rd';
32+
break;
33+
}
34+
}
35+
36+
return $number . $ending;
37+
}
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* By adding type hints and enabling strict type checking, code can become
5+
* easier to read, self-documenting and reduce the number of potential bugs.
6+
* By default, type declarations are non-strict, which means they will attempt
7+
* to change the original type to match the type specified by the
8+
* type-declaration.
9+
*
10+
* In other words, if you pass a string to a function requiring a float,
11+
* it will attempt to convert the string value to a float.
12+
*
13+
* To enable strict mode, a single declare directive must be placed at the top
14+
* of the file.
15+
* This means that the strictness of typing is configured on a per-file basis.
16+
* This directive not only affects the type declarations of parameters, but also
17+
* a function's return type.
18+
*
19+
* For more info review the Concept on strict type checking in the PHP track
20+
* <link>.
21+
*
22+
* To disable strict typing, comment out the directive below.
23+
*/
24+
25+
declare(strict_types=1);
26+
27+
function format(string $name, int $number): string
28+
{
29+
throw new \BadFunctionCallException(sprintf('Implement the %s function', __FUNCTION__));
30+
}

0 commit comments

Comments
 (0)