Skip to content

Commit 260e40a

Browse files
committed
Add line-up exercise
1 parent 1416f46 commit 260e40a

File tree

9 files changed

+276
-0
lines changed

9 files changed

+276
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@
511511
],
512512
"difficulty": 1
513513
},
514+
{
515+
"slug": "line-up",
516+
"name": "Line Up",
517+
"uuid": "e09d877e-489b-4dbd-89c5-f6b15e867b67",
518+
"practices": ["string-formatting"],
519+
"prerequisites": ["basics", "strings"],
520+
"difficulty": 1
521+
},
514522
{
515523
"slug": "difference-of-squares",
516524
"name": "Difference of Squares",
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 (unless ending in 11) → `"st"`
9+
- Numbers ending in 2 (unless ending in 12) → `"nd"`
10+
- Numbers ending in 3 (unless ending in 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.py"
8+
],
9+
"test": [
10+
"line_up_test.py"
11+
],
12+
"example": [
13+
".meta/example.py"
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+
def line_up(name, number):
2+
suffix = get_suffix(number)
3+
return f"{name}, you are the {number}{suffix} customer we serve today. Thank you!"
4+
5+
6+
def get_suffix(number):
7+
if 11 <= number % 100 <= 13:
8+
return "th"
9+
10+
mod_10 = number % 10
11+
12+
if mod_10 == 1:
13+
return "st"
14+
if mod_10 == 2:
15+
return "nd"
16+
if mod_10 == 3:
17+
return "rd"
18+
19+
return "th"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
{{ macros.header(imports=['line_up']) }}
5+
6+
class {{ exercise | camel_case }}Test(unittest.TestCase):
7+
{% for case in cases -%}
8+
def test_{{ case["description"] | to_snake }}(self):
9+
self.assertEqual(line_up("{{ case["input"]["name"] }}", {{ case["input"]["number"] }}), "{{ case["expected"] }}")
10+
{% endfor -%}
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def line_up(name, number):
2+
pass
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# These tests are auto-generated with test data from:
2+
# https://github.com/exercism/problem-specifications/tree/main/exercises/line-up/canonical-data.json
3+
# File last updated on 2026-01-23
4+
5+
import unittest
6+
7+
from line_up import (
8+
line_up,
9+
)
10+
11+
12+
class LineUpTest(unittest.TestCase):
13+
def test_format_smallest_non_exceptional_ordinal_numeral_4(self):
14+
self.assertEqual(
15+
line_up("Gianna", 4),
16+
"Gianna, you are the 4th customer we serve today. Thank you!",
17+
)
18+
19+
def test_format_greatest_single_digit_non_exceptional_ordinal_numeral_9(self):
20+
self.assertEqual(
21+
line_up("Maarten", 9),
22+
"Maarten, you are the 9th customer we serve today. Thank you!",
23+
)
24+
25+
def test_format_non_exceptional_ordinal_numeral_5(self):
26+
self.assertEqual(
27+
line_up("Petronila", 5),
28+
"Petronila, you are the 5th customer we serve today. Thank you!",
29+
)
30+
31+
def test_format_non_exceptional_ordinal_numeral_6(self):
32+
self.assertEqual(
33+
line_up("Attakullakulla", 6),
34+
"Attakullakulla, you are the 6th customer we serve today. Thank you!",
35+
)
36+
37+
def test_format_non_exceptional_ordinal_numeral_7(self):
38+
self.assertEqual(
39+
line_up("Kate", 7),
40+
"Kate, you are the 7th customer we serve today. Thank you!",
41+
)
42+
43+
def test_format_non_exceptional_ordinal_numeral_8(self):
44+
self.assertEqual(
45+
line_up("Maximiliano", 8),
46+
"Maximiliano, you are the 8th customer we serve today. Thank you!",
47+
)
48+
49+
def test_format_exceptional_ordinal_numeral_1(self):
50+
self.assertEqual(
51+
line_up("Mary", 1),
52+
"Mary, you are the 1st customer we serve today. Thank you!",
53+
)
54+
55+
def test_format_exceptional_ordinal_numeral_2(self):
56+
self.assertEqual(
57+
line_up("Haruto", 2),
58+
"Haruto, you are the 2nd customer we serve today. Thank you!",
59+
)
60+
61+
def test_format_exceptional_ordinal_numeral_3(self):
62+
self.assertEqual(
63+
line_up("Henriette", 3),
64+
"Henriette, you are the 3rd customer we serve today. Thank you!",
65+
)
66+
67+
def test_format_smallest_two_digit_non_exceptional_ordinal_numeral_10(self):
68+
self.assertEqual(
69+
line_up("Alvarez", 10),
70+
"Alvarez, you are the 10th customer we serve today. Thank you!",
71+
)
72+
73+
def test_format_non_exceptional_ordinal_numeral_11(self):
74+
self.assertEqual(
75+
line_up("Jacqueline", 11),
76+
"Jacqueline, you are the 11th customer we serve today. Thank you!",
77+
)
78+
79+
def test_format_non_exceptional_ordinal_numeral_12(self):
80+
self.assertEqual(
81+
line_up("Juan", 12),
82+
"Juan, you are the 12th customer we serve today. Thank you!",
83+
)
84+
85+
def test_format_non_exceptional_ordinal_numeral_13(self):
86+
self.assertEqual(
87+
line_up("Patricia", 13),
88+
"Patricia, you are the 13th customer we serve today. Thank you!",
89+
)
90+
91+
def test_format_exceptional_ordinal_numeral_21(self):
92+
self.assertEqual(
93+
line_up("Washi", 21),
94+
"Washi, you are the 21st customer we serve today. Thank you!",
95+
)
96+
97+
def test_format_exceptional_ordinal_numeral_62(self):
98+
self.assertEqual(
99+
line_up("Nayra", 62),
100+
"Nayra, you are the 62nd customer we serve today. Thank you!",
101+
)
102+
103+
def test_format_exceptional_ordinal_numeral_100(self):
104+
self.assertEqual(
105+
line_up("John", 100),
106+
"John, you are the 100th customer we serve today. Thank you!",
107+
)
108+
109+
def test_format_exceptional_ordinal_numeral_101(self):
110+
self.assertEqual(
111+
line_up("Zeinab", 101),
112+
"Zeinab, you are the 101st customer we serve today. Thank you!",
113+
)
114+
115+
def test_format_non_exceptional_ordinal_numeral_112(self):
116+
self.assertEqual(
117+
line_up("Knud", 112),
118+
"Knud, you are the 112th customer we serve today. Thank you!",
119+
)
120+
121+
def test_format_exceptional_ordinal_numeral_123(self):
122+
self.assertEqual(
123+
line_up("Yma", 123),
124+
"Yma, you are the 123rd customer we serve today. Thank you!",
125+
)

0 commit comments

Comments
 (0)