49
6
Introduction
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?
Mechanics
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.
Task
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 False
.
Scoring
Standard code golf rules - the winner is the code with the fewest bytes.
Bonuses:
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 standardTrue
output.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
Crash
if a crash is unavoidable, orStuck
if the car is stuck in the obstacle course forever. These outputs would replace the standardFalse
output for an unsolvable map.
Example
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 SSSSRSRRRSRSSRRRSSRSSS
.
This question reminded me of an odd route I took to a previous work site. The route that I took was literally exactly 7 lefts from home to work, and vice versa (7 rights from work to home). No joke. I took that route for a while before I realized it. – Aaron – 2017-07-13T18:01:40.763
That's a funny story. Hopefully the route didn't cross over itself! – phosgene – 2017-09-28T07:59:01.147
Could you also provide example inputs for for the
Crash
andStuck
cases? – Martin Ender – 2014-10-03T11:34:37.6332
I wrote some incredibly simple test cases for
– undergroundmonorail – 2014-10-03T14:31:30.280Crash
andStuck
. They're here because of how long they are. Row 2 filled, everything else empty ->Crash
. Row 7 filled, everything else empty ->Stuck
3I'm confused about percentage points (as opposed to percentages). Getting either bonus multiplies your score by 0.9. Does getting both multiply it by 0.8 or 0.9^2? – undergroundmonorail – 2014-10-03T14:35:11.023
Another question: Can we exit with an exception or do we have to go out gracefully? – undergroundmonorail – 2014-10-03T14:41:01.827
1I was attempting to imply that the percentage points are deducted from the actual number of code bytes, so claiming both bonuses results in multiplication by 0.8. Sorry if it wasn't clear. – phosgene – 2014-10-03T16:12:00.900
1Exiting with an exception is OK, as long as that exception alerts the viewer about the (non)existence of a solution. No ambiguity allowed, basically. – phosgene – 2014-10-03T16:14:02.443
For Stuck or Crash, could we return something like 'S' or 'C'? Or does it have to be the whole word? This doesn't seem ambiguous to me. – FryAmTheEggman – 2014-10-03T17:00:06.120
3Sure, S and C are fine. My outputs were only suggestions. – phosgene – 2014-10-03T17:01:53.487
13"Two wrongs don't make a right, but three lefts do." - Dad. – hoosierEE – 2014-10-03T21:07:32.050
I actually considered using 'three lefts' in the title. – phosgene – 2014-10-03T21:08:50.097
2"Your car can make only zero or three lefts!" – feersum – 2014-10-04T16:14:20.253
@feersum "Your car is pretty shitty!" – flawr – 2014-10-06T19:52:01.717
@flawr But it's very fast and that's what's important! – feersum – 2014-10-07T13:31:12.460
Is it ok if the function takes a named argument as the board, instead of just the argument? i.e.
f(b=board)
? – FryAmTheEggman – 2014-10-07T14:03:22.5471Sure, the input formats is not particularly important. – phosgene – 2014-10-07T17:28:26.497