Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@
"prerequisites": [],
"difficulty": 6
},
{
"slug": "robot-name",
"name": "Robot Name",
"uuid": "c768d50f-3c25-44cc-8a83-fe8cc9d7e93f",
"practices": [],
"prerequisites": [],
"difficulty": 6
},
{
"slug": "swift-scheduling",
"name": "Swift Scheduling",
Expand Down
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.
21 changes: 21 additions & 0 deletions exercises/practice/robot-name/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"authors": [
"IsaacG"
],
"files": {
"solution": [
"robot_name.gd"
],
"test": [
"robot_name_test.gd",
"run_tests",
"lib/test_runner.gd",
"project.godot"
],
"example": [
".meta/example.gd"
]
},
"blurb": "Manage robot factory settings.",
"source": "A debugging session with Paul Blackwell at gSchool."
}
26 changes: 26 additions & 0 deletions exercises/practice/robot-name/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const ALPHA = "QWERTYUIOPASDFGHJKLZXCVBNM"


class Robot:
var name = null
var _rng = null
static var names = {}

func _init(rng):
_rng = rng
reset()

func gen_name():
return (
"%s%s%03d"
% [
ALPHA[_rng.randi_range(0, 25)],
ALPHA[_rng.randi_range(0, 25)],
_rng.randi_range(0, 999),
]
)

func reset():
while name == null or name in Robot.names:
name = gen_name()
Robot.names[name] = true
Loading
Loading