You have the misfortune of being stuck in a runaway car on an obstacle course. All of the car's features are non-responsive, save for the steering system, which is damaged. It can drive straight, or it can turn right. Can the car be guided to safety?
Your car begins in the upper-left corner of an 8x8 map, and is trying to get to safety in the lower-right corner. The car has an orientation (initially to the right), measured in 90-degree increments. The car can perform one of two actions:
- Drive one square forward, or
- Turn 90 degrees clockwise, then drive one square forward
Note that the car is unable to turn sharply enough to perform a 180-degree turn on a single square.
Some of the squares are obstacles. If the car enters an obstacle square, it crashes. Everything outside the 8x8 course is assumed to be obstacles, so driving off the course is equivalent to crashing.
The lower-right square is the safe square, which allows the car to escape the obstacle course. The starting square and safe square are assumed not to be obstacles.
You must write a program or function which takes as its input an 8x8 array (matrix, list of lists, etc.), representing the obstacle course. The program returns or prints a Boolean, or something similarly truthy. If it's possible for the car to make it to the safe square without crashing (i.e., if the map is solvable), the output is
True, otherwise, it's
Standard code golf rules - the winner is the code with the fewest bytes.
If, for a solvable map, your code outputs a valid series of driver inputs which guide the car to the safe square, deduct 10 percentage points from your score. An example output format might be
SRSSR(indicating Straight, Right, Straight, Straight, Right). This output would replace the standard
If, for an unsolvable map, your code's output distinguishes between situations where a crash is unavoidable, and situations where it's possible to drive around the obstacle course forever, deduct 10 percentage points from your score. An example output might be
Crashif a crash is unavoidable, or
Stuckif the car is stuck in the obstacle course forever. These outputs would replace the standard
Falseoutput for an unsolvable map.
If the program is given an 8x8 array such as this:
[[0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 0, 0, 0, 1, 0]]
It would be interpreted as a map like this, with black squares indicating obstacles:
And a possible solution might be:
Since a solution exists, the program should return/print
True for this map. The sequence of moves shown here is
Stuck. They're here because of how long they are. Row 2 filled, everything else empty ->
Crash. Row 7 filled, everything else empty ->