Skip to content

Commit 3e1484b

Browse files
Add robot-name exercise (#130)
* Add `robot-name` exercise * Add `robot-name` exercise
1 parent 37337a2 commit 3e1484b

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@
242242
"prerequisites": [],
243243
"difficulty": 3
244244
},
245+
{
246+
"slug": "robot-name",
247+
"name": "Robot Name",
248+
"uuid": "d5215b24-89a9-40c0-a397-d2d4b74d6544",
249+
"practices": [],
250+
"prerequisites": [],
251+
"difficulty": 3
252+
},
245253
{
246254
"slug": "queen-attack",
247255
"name": "Queen Attack",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Instructions append
2+
3+
```exercism/note
4+
As Uiua does **not** have mutable state, the exercise only expects you to generate random names.
5+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Instructions
2+
3+
Manage robot factory settings.
4+
5+
When a robot comes off the factory floor, it has no name.
6+
7+
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.
8+
9+
Every once in a while we need to reset a robot to its factory settings, which means that its name gets wiped.
10+
The next time you ask, that robot will respond with a new random name.
11+
12+
The names must be random: they should not follow a predictable sequence.
13+
Using random names means a risk of collisions.
14+
Your solution must ensure that every existing robot has a unique name.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"authors": [
3+
"erikschierboom"
4+
],
5+
"files": {
6+
"solution": [
7+
"robot-name.ua"
8+
],
9+
"test": [
10+
"tests.ua"
11+
],
12+
"example": [
13+
".meta/example.ua"
14+
]
15+
},
16+
"blurb": "Manage robot factory settings.",
17+
"source": "A debugging session with Paul Blackwell at gSchool."
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RandomRange ← + ⌊× ⊙[⍥⚂]
2+
RandomLetters ← (RandomRange 26 2 @A)
3+
RandomDigits ← (RandomRange 10 3 @0)
4+
GenerateName ← (⊂ RandomLetters RandomDigits)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generate a random name for a robot
2+
# Name
3+
GenerateName ← |0 (⍤. "Please implement GenerateName" 0)
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
~ "robot-name.ua" ~ GenerateName
2+
3+
# Name has correct format
4+
⍤⤙≍ 1 ±⧻♭ regex "^[A-Z]{2}\\d{3}$" GenerateName()
5+
6+
# Name is generated randomly
7+
⍤⤙≍ 25 ⧻◴ [⍥GenerateName] 25

0 commit comments

Comments
 (0)