From 4361f1ce814bc9b34191af2832abf387e637a09a Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Tue, 17 Dec 2024 12:25:03 +0100 Subject: [PATCH] Add `robot-name` exercise --- config.json | 8 ++++++++ .../robot-name/.docs/instructions.append.md | 5 +++++ .../practice/robot-name/.docs/instructions.md | 14 ++++++++++++++ .../practice/robot-name/.meta/config.json | 18 ++++++++++++++++++ exercises/practice/robot-name/.meta/example.ua | 3 +++ exercises/practice/robot-name/robot-name.ua | 3 +++ exercises/practice/robot-name/tests.ua | 7 +++++++ 7 files changed, 58 insertions(+) create mode 100644 exercises/practice/robot-name/.docs/instructions.append.md create mode 100644 exercises/practice/robot-name/.docs/instructions.md create mode 100644 exercises/practice/robot-name/.meta/config.json create mode 100644 exercises/practice/robot-name/.meta/example.ua create mode 100644 exercises/practice/robot-name/robot-name.ua create mode 100644 exercises/practice/robot-name/tests.ua diff --git a/config.json b/config.json index 85dbb26..4ce431b 100644 --- a/config.json +++ b/config.json @@ -242,6 +242,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "robot-name", + "name": "Robot Name", + "uuid": "d5215b24-89a9-40c0-a397-d2d4b74d6544", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "queen-attack", "name": "Queen Attack", diff --git a/exercises/practice/robot-name/.docs/instructions.append.md b/exercises/practice/robot-name/.docs/instructions.append.md new file mode 100644 index 0000000..3baff26 --- /dev/null +++ b/exercises/practice/robot-name/.docs/instructions.append.md @@ -0,0 +1,5 @@ +# Instructions append + +```exercism/note +As Uiua does **not** have mutable state, the exercise only expects you to generate random names. +``` diff --git a/exercises/practice/robot-name/.docs/instructions.md b/exercises/practice/robot-name/.docs/instructions.md new file mode 100644 index 0000000..fca3a41 --- /dev/null +++ b/exercises/practice/robot-name/.docs/instructions.md @@ -0,0 +1,14 @@ +# Instructions + +Manage robot factory settings. + +When a robot comes off the factory floor, it has no name. + +The first time you turn on a robot, a random name is generated in the format of two uppercase letters followed by three digits, such as RX837 or BC811. + +Every once in a while we need to reset a robot to its factory settings, which means that its name gets wiped. +The next time you ask, that robot will respond with a new random name. + +The names must be random: they should not follow a predictable sequence. +Using random names means a risk of collisions. +Your solution must ensure that every existing robot has a unique name. diff --git a/exercises/practice/robot-name/.meta/config.json b/exercises/practice/robot-name/.meta/config.json new file mode 100644 index 0000000..9ed49f2 --- /dev/null +++ b/exercises/practice/robot-name/.meta/config.json @@ -0,0 +1,18 @@ +{ + "authors": [ + "erikschierboom" + ], + "files": { + "solution": [ + "robot-name.ua" + ], + "test": [ + "tests.ua" + ], + "example": [ + ".meta/example.ua" + ] + }, + "blurb": "Manage robot factory settings.", + "source": "A debugging session with Paul Blackwell at gSchool." +} diff --git a/exercises/practice/robot-name/.meta/example.ua b/exercises/practice/robot-name/.meta/example.ua new file mode 100644 index 0000000..6724534 --- /dev/null +++ b/exercises/practice/robot-name/.meta/example.ua @@ -0,0 +1,3 @@ +RandomLetters ← (+@A ⌊×26 [⍥⚂] 2) +RandomDigits ← (+@0 ⌊×10 [⍥⚂] 3) +GenerateName ← (⊂ RandomLetters RandomDigits) diff --git a/exercises/practice/robot-name/robot-name.ua b/exercises/practice/robot-name/robot-name.ua new file mode 100644 index 0000000..157b3c2 --- /dev/null +++ b/exercises/practice/robot-name/robot-name.ua @@ -0,0 +1,3 @@ +# Generate a random name for a robot +# Name +GenerateName ← |0 (⍤. "Please implement GenerateName" 0) diff --git a/exercises/practice/robot-name/tests.ua b/exercises/practice/robot-name/tests.ua new file mode 100644 index 0000000..05fb7c7 --- /dev/null +++ b/exercises/practice/robot-name/tests.ua @@ -0,0 +1,7 @@ +~ "robot-name.ua" ~ GenerateName + +# Name has correct format +⍤⤙≍ 1 ±⧻♭ regex "^[A-Z]{2}\\d{3}$" GenerateName() + +# Name is generated randomly +⍤⤙≍ 25 ⧻◴ [⍥GenerateName] 25