16
1
Your goal is to write a program that creates a random 10x10 map using 0
, 1
, and 2
, and finds the shortest path from top-left to bottom-right, assuming that:
0 represents a grass field: anyone can walk on it;
1 represents a wall: you cannot cross it;
2 represents a portal: when entering a portal, you can move to any other portal in the map.
Specs:
- The top-left element and the bottom-right one must be 0;
- When creating the random map, every field should have 60% chance of being a 0, 30% of being a 1 and 10% of being a 2;
- You can move in any adjacent field (even diagonal ones);
- Your program should output the map and the number of steps of the shortest path;
- If there isn't a valid path that leads to the bottom-right field, your program should output the map only;
- You can use any resource you'd like to;
- Shortest code wins.
Calculating steps:
A step is an actual movement; every time you change field, you increment the counter.
Output:
0000100200
0100100010
1000000111
0002001000
1111100020
0001111111
0001001000
0020001111
1100110000
0000020100
9
Can't we just produce the program for the shortest path? Generating is another question. – Mikaël Mayer – 2014-01-04T15:55:13.060
You didn't specify that the random map must be different each time :) – marinus – 2014-01-04T15:59:35.253
@marinus LoooL! Well, in the specs I wrote the generating chances, so I guess that writing a standard map with 60 0, 30 1 and 10 2 won't be a right solution :P – Vereos – 2014-01-04T16:04:20.217
@MikaëlMayer I guess you've got a point, but I think it would be more challenging like this. Am I wrong? – Vereos – 2014-01-04T16:05:08.750
As this is a code-golf question, the winning criteria is shortest code. What happens if that code is really slow and takes centuries to run? – Victor Stafusa – 2014-01-04T18:11:57.130
If it does work, it's ok. Since it's code-golf, only the shortest code wins. – Vereos – 2014-01-04T21:12:28.577