From 9008b8f9b03a47034c2306f1e2d5cffafad631b9 Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Fri, 10 Oct 2025 18:47:27 +1100 Subject: [PATCH] Add line-up --- config.json | 8 +++ .../practice/line-up/.docs/instructions.md | 19 ++++++ .../practice/line-up/.docs/introduction.md | 7 ++ exercises/practice/line-up/.meta/config.json | 19 ++++++ exercises/practice/line-up/.meta/tests.toml | 67 +++++++++++++++++++ exercises/practice/line-up/example/LineUp.idr | 13 ++++ exercises/practice/line-up/line-up.ipkg | 3 + exercises/practice/line-up/pack.toml | 10 +++ exercises/practice/line-up/src/LineUp.idr | 5 ++ exercises/practice/line-up/test/src/Main.idr | 57 ++++++++++++++++ exercises/practice/line-up/test/test.ipkg | 6 ++ generators/exercises/line_up.py | 6 ++ generators/generate.py | 8 ++- 13 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 exercises/practice/line-up/.docs/instructions.md create mode 100644 exercises/practice/line-up/.docs/introduction.md create mode 100644 exercises/practice/line-up/.meta/config.json create mode 100644 exercises/practice/line-up/.meta/tests.toml create mode 100644 exercises/practice/line-up/example/LineUp.idr create mode 100644 exercises/practice/line-up/line-up.ipkg create mode 100644 exercises/practice/line-up/pack.toml create mode 100644 exercises/practice/line-up/src/LineUp.idr create mode 100644 exercises/practice/line-up/test/src/Main.idr create mode 100644 exercises/practice/line-up/test/test.ipkg create mode 100644 generators/exercises/line_up.py diff --git a/config.json b/config.json index 110c078..49dc0e1 100644 --- a/config.json +++ b/config.json @@ -248,6 +248,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "line-up", + "name": "Line Up", + "uuid": "4a2e73b8-00a0-425b-a3fb-84b5702b067c", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "nucleotide-count", "name": "Nucleotide Count", diff --git a/exercises/practice/line-up/.docs/instructions.md b/exercises/practice/line-up/.docs/instructions.md new file mode 100644 index 0000000..fb41d4c --- /dev/null +++ b/exercises/practice/line-up/.docs/instructions.md @@ -0,0 +1,19 @@ +# Instructions + +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]. +Yaʻqūb expects to use numbers from 1 up to 999. + +Rules: + +- Numbers ending in 1 (except for 11) → `"st"` +- Numbers ending in 2 (except for 12) → `"nd"` +- Numbers ending in 3 (except for 13) → `"rd"` +- All other numbers → `"th"` + +Examples: + +- `"Mary", 1` → `"Mary, you are the 1st customer we serve today. Thank you!"` +- `"John", 12` → `"John, you are the 12th customer we serve today. Thank you!"` +- `"Dahir", 162` → `"Dahir, you are the 162nd customer we serve today. Thank you!"` + +[ordinal-numeral]: https://en.wikipedia.org/wiki/Ordinal_numeral diff --git a/exercises/practice/line-up/.docs/introduction.md b/exercises/practice/line-up/.docs/introduction.md new file mode 100644 index 0000000..ea07268 --- /dev/null +++ b/exercises/practice/line-up/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +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. +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. + +To make the customers feel special, he does not want the ticket to have only a number on it. +They shall get a proper English sentence with their name and number on it. diff --git a/exercises/practice/line-up/.meta/config.json b/exercises/practice/line-up/.meta/config.json new file mode 100644 index 0000000..f80944a --- /dev/null +++ b/exercises/practice/line-up/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "keiravillekode" + ], + "files": { + "solution": [ + "src/LineUp.idr" + ], + "test": [ + "test/src/Main.idr" + ], + "example": [ + "example/LineUp.idr" + ] + }, + "blurb": "Help lining up customers at Yaʻqūb's Deli.", + "source": "mk-mxp, based on previous work from Exercism contributors codedge and neenjaw", + "source_url": "https://forum.exercism.org/t/new-exercise-ordinal-numbers/19147" +} diff --git a/exercises/practice/line-up/.meta/tests.toml b/exercises/practice/line-up/.meta/tests.toml new file mode 100644 index 0000000..36fdf1d --- /dev/null +++ b/exercises/practice/line-up/.meta/tests.toml @@ -0,0 +1,67 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[7760d1b8-4864-4db4-953b-0fa7c047dbc0] +description = "format smallest non-exceptional ordinal numeral 4" + +[e8b7c715-6baa-4f7b-8fb3-2fa48044ab7a] +description = "format greatest single digit non-exceptional ordinal numeral 9" + +[f370aae9-7ae7-4247-90ce-e8ff8c6934df] +description = "format non-exceptional ordinal numeral 5" + +[37f10dea-42a2-49de-bb92-0b690b677908] +description = "format non-exceptional ordinal numeral 6" + +[d8dfb9a2-3a1f-4fee-9dae-01af3600054e] +description = "format non-exceptional ordinal numeral 7" + +[505ec372-1803-42b1-9377-6934890fd055] +description = "format non-exceptional ordinal numeral 8" + +[8267072d-be1f-4f70-b34a-76b7557a47b9] +description = "format exceptional ordinal numeral 1" + +[4d8753cb-0364-4b29-84b8-4374a4fa2e3f] +description = "format exceptional ordinal numeral 2" + +[8d44c223-3a7e-4f48-a0ca-78e67bf98aa7] +description = "format exceptional ordinal numeral 3" + +[6c4f6c88-b306-4f40-bc78-97cdd583c21a] +description = "format smallest two digit non-exceptional ordinal numeral 10" + +[e257a43f-d2b1-457a-97df-25f0923fc62a] +description = "format non-exceptional ordinal numeral 11" + +[bb1db695-4d64-457f-81b8-4f5a2107e3f4] +description = "format non-exceptional ordinal numeral 12" + +[60a3187c-9403-4835-97de-4f10ebfd63e2] +description = "format non-exceptional ordinal numeral 13" + +[2bdcebc5-c029-4874-b6cc-e9bec80d603a] +description = "format exceptional ordinal numeral 21" + +[74ee2317-0295-49d2-baf0-d56bcefa14e3] +description = "format exceptional ordinal numeral 62" + +[b37c332d-7f68-40e3-8503-e43cbd67a0c4] +description = "format exceptional ordinal numeral 100" + +[0375f250-ce92-4195-9555-00e28ccc4d99] +description = "format exceptional ordinal numeral 101" + +[0d8a4974-9a8a-45a4-aca7-a9fb473c9836] +description = "format non-exceptional ordinal numeral 112" + +[06b62efe-199e-4ce7-970d-4bf73945713f] +description = "format exceptional ordinal numeral 123" diff --git a/exercises/practice/line-up/example/LineUp.idr b/exercises/practice/line-up/example/LineUp.idr new file mode 100644 index 0000000..ffa254c --- /dev/null +++ b/exercises/practice/line-up/example/LineUp.idr @@ -0,0 +1,13 @@ +module LineUp + +suffix : Int -> Int -> String +suffix 1 _ = "th" +suffix _ 1 = "st" +suffix _ 2 = "nd" +suffix _ 3 = "rd" +suffix _ _ = "th" + +export +format : String -> Int -> String +format name number = + name ++ ", you are the " ++ (show number) ++ (suffix (number `div` 10 `mod` 10) (number `mod` 10)) ++ " customer we serve today. Thank you!" diff --git a/exercises/practice/line-up/line-up.ipkg b/exercises/practice/line-up/line-up.ipkg new file mode 100644 index 0000000..a52a00a --- /dev/null +++ b/exercises/practice/line-up/line-up.ipkg @@ -0,0 +1,3 @@ +package line-up +modules = LineUp +sourcedir = "src" diff --git a/exercises/practice/line-up/pack.toml b/exercises/practice/line-up/pack.toml new file mode 100644 index 0000000..25a9b66 --- /dev/null +++ b/exercises/practice/line-up/pack.toml @@ -0,0 +1,10 @@ +[custom.all.line-up] +type = "local" +path = "." +ipkg = "line-up.ipkg" +test = "test/test.ipkg" + +[custom.all.line-up-test] +type = "local" +path = "test" +ipkg = "test.ipkg" diff --git a/exercises/practice/line-up/src/LineUp.idr b/exercises/practice/line-up/src/LineUp.idr new file mode 100644 index 0000000..43c88d0 --- /dev/null +++ b/exercises/practice/line-up/src/LineUp.idr @@ -0,0 +1,5 @@ +module LineUp + +export +format : String -> Int -> String +format name number = ?format_rhs diff --git a/exercises/practice/line-up/test/src/Main.idr b/exercises/practice/line-up/test/src/Main.idr new file mode 100644 index 0000000..b3e6ae8 --- /dev/null +++ b/exercises/practice/line-up/test/src/Main.idr @@ -0,0 +1,57 @@ +module Main + +import System +import Tester +import Tester.Runner + +import LineUp + +tests : List Test +tests = + [ test "format smallest non-exceptional ordinal numeral 4" ( + assertEq (format "Gianna" 4) "Gianna, you are the 4th customer we serve today. Thank you!") + , test "format greatest single digit non-exceptional ordinal numeral 9" ( + assertEq (format "Maarten" 9) "Maarten, you are the 9th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 5" ( + assertEq (format "Petronila" 5) "Petronila, you are the 5th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 6" ( + assertEq (format "Attakullakulla" 6) "Attakullakulla, you are the 6th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 7" ( + assertEq (format "Kate" 7) "Kate, you are the 7th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 8" ( + assertEq (format "Maximiliano" 8) "Maximiliano, you are the 8th customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 1" ( + assertEq (format "Mary" 1) "Mary, you are the 1st customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 2" ( + assertEq (format "Haruto" 2) "Haruto, you are the 2nd customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 3" ( + assertEq (format "Henriette" 3) "Henriette, you are the 3rd customer we serve today. Thank you!") + , test "format smallest two digit non-exceptional ordinal numeral 10" ( + assertEq (format "Alvarez" 10) "Alvarez, you are the 10th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 11" ( + assertEq (format "Jacqueline" 11) "Jacqueline, you are the 11th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 12" ( + assertEq (format "Juan" 12) "Juan, you are the 12th customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 13" ( + assertEq (format "Patricia" 13) "Patricia, you are the 13th customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 21" ( + assertEq (format "Washi" 21) "Washi, you are the 21st customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 62" ( + assertEq (format "Nayra" 62) "Nayra, you are the 62nd customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 100" ( + assertEq (format "John" 100) "John, you are the 100th customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 101" ( + assertEq (format "Zeinab" 101) "Zeinab, you are the 101st customer we serve today. Thank you!") + , test "format non-exceptional ordinal numeral 112" ( + assertEq (format "Knud" 112) "Knud, you are the 112th customer we serve today. Thank you!") + , test "format exceptional ordinal numeral 123" ( + assertEq (format "Yma" 123) "Yma, you are the 123rd customer we serve today. Thank you!") + ] + +export +main : IO () +main = do + success <- runTests tests + if success + then putStrLn "All tests passed" + else exitFailure diff --git a/exercises/practice/line-up/test/test.ipkg b/exercises/practice/line-up/test/test.ipkg new file mode 100644 index 0000000..c2264a1 --- /dev/null +++ b/exercises/practice/line-up/test/test.ipkg @@ -0,0 +1,6 @@ +package line-up-test +depends = line-up + , tester +main = Main +executable = "line-up-test" +sourcedir = "src" diff --git a/generators/exercises/line_up.py b/generators/exercises/line_up.py new file mode 100644 index 0000000..eecf051 --- /dev/null +++ b/generators/exercises/line_up.py @@ -0,0 +1,6 @@ +def generate_test(case): + property = case["property"] + expected = case["expected"] + name = case["input"]["name"] + number = case["input"]["number"] + return f'\n assertEq ({property} "{name}" {number}) "{expected}"' diff --git a/generators/generate.py b/generators/generate.py index 50e18f4..7453ab3 100755 --- a/generators/generate.py +++ b/generators/generate.py @@ -6,7 +6,13 @@ import os import subprocess import sys -import tomllib + +# tomllib is available in the standard library as of Python 3.11 +# When using an older release, we use the compatible tomli +try: + import tomllib +except ModuleNotFoundError: + import tomli as tomllib PREFIX = """module Main