Skip to content

Commit

Permalink
Add robot-name exercise (#130)
Browse files Browse the repository at this point in the history
* Add `robot-name` exercise

* Add `robot-name` exercise
  • Loading branch information
ErikSchierboom authored Dec 19, 2024
1 parent 37337a2 commit 3e1484b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions exercises/practice/robot-name/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Instructions append

```exercism/note
As Uiua does **not** have mutable state, the exercise only expects you to generate random names.
```
14 changes: 14 additions & 0 deletions exercises/practice/robot-name/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions exercises/practice/robot-name/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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."
}
4 changes: 4 additions & 0 deletions exercises/practice/robot-name/.meta/example.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RandomRange ← + ⌊× ⊙[⍥⚂]
RandomLetters ← (RandomRange 26 2 @A)
RandomDigits ← (RandomRange 10 3 @0)
GenerateName ← (⊂ RandomLetters RandomDigits)
3 changes: 3 additions & 0 deletions exercises/practice/robot-name/robot-name.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generate a random name for a robot
# Name
GenerateName ← |0 (⍤. "Please implement GenerateName" 0)
7 changes: 7 additions & 0 deletions exercises/practice/robot-name/tests.ua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3e1484b

Please sign in to comment.