I have a problem with solving the "Dispersion V2" puzzle on robozzle.com:
The puzzle has a robot that can be moved and turned with a program. The goal of the puzzle is to have the robot visit all cells that have a star -- in this case just one.
The robot can perform actions unconditionally or conditional on a certain cell color.
This particular level looks like a rectangular spiral, the robot's initial position at bottom-left.
- Every side of the spiral has 4 blocks of red;
- Every edge(turn) is red block
- Every side of the spiral is shorter than prev.side by 1 block
I need to write an algorithm using 4 functions only, named F1, F2, F3, and F4. Each function can only perform 2 commands, except F2 which can do 3 commands. Here you see the empty template for the program (the greyed numbers are just placeholders where the actual commands must be placed):
The available commands that these functions can use are:
↑
: move forward↰
: turn left↱
: turn rightFx
: call function (eitherF1
,F2
,F3
,F4
). Recursion is fine.
These commands can be accompanied by a color or not. When they have a color, they only have effect when the current cell (having the robot) has that same color. When it is different, the command is ignored, and execution continues with the next command.
Once the puzzle is solved the program will halt (no matter how deep the call stack is) with success. If the robot is steered off the grid, the program will halt with a failure.
What I have now:
How I can solve this puzzle?