Jump to content
BrainDen.com - Brain Teasers
  • 1

Dumb robot


harey
 Share

Question

Each square of an n x n grid of squares is either filled with cement blocks or left empty, such that there is at least one path from the top left corner to the bottom right corner of the grid. Outside the grid everything is filled with cement. A robot is currently located at the top left corner and wants to get to the bottom right corner, but it only knows the value of n and doesn't know the layout of the grid. It also has no method of observing its surroundings, and it is your job to give it instructions to ensure it ends up at its destination. Your instructions should be a finite list of directions (Up, Down, Left, Right) - the robot will try to move in the indicated directions in order, and, if there is a cement wall in the way at some step, it will simply fail to move in the corresponding direction and continue on with the next instruction in the list. Since the robot has no way of sensing whether it has reached its destination, it might reach the destination somewhere in the middle of your list of instructions and then later leave. The goal is to give a list of instructions, depending only on n, such that after following your instructions the robot is guaranteed to end its journey in the bottom right corner of the grid.

The bad news: I do not know the solution and I cannot ask for hints.

Link to comment
Share on other sites

17 answers to this question

Recommended Posts

  • 0
  On 3/11/2018 at 9:43 PM, CaptainEd said:

I gather that when it sees Left, it goes as far left as possible until it hits cement.

Expand  

An interesting variant. The problem states "there is a path", but it does not state "there is a path for the robot".

I think it is easier we stay with moving just to the next square.

Edited by harey
Link to comment
Share on other sites

  • 0
  Reveal hidden contents
Edited by Molly Mae
Link to comment
Share on other sites

  • 0
  On 3/12/2018 at 7:17 PM, CaptainEd said:

Harey, can we assume as Molly Mae did, that there is no maze, but only a simple path? I assumed otherwise, that it can be a maze, so I imagined a figure H, with only two cells with cement (top center and bottom center).

Expand  

I do not really understand what you mean by "simple path", but I think the answer is no. The figure H is OK, but you can very well have:

* * *    * * c   * * *
c * c   c * *   * c *
* * *    * * *   * c * ...

Your list must work for all these cases, as well as for all grids where there is/are one/three/four cement blocks. i.e. the solution Molly Mae proposed would not work for the first maze (so it does not matter anymore that it works for the 2nd and 3rd).

Even calculating the number of possibilities for 2 blocks gives me headaches. 7 * 6 / 2? Wrong, the robot must be free to leave the corner and the lower right corner must remain accessible.

To get insane...

Link to comment
Share on other sites

  • 0

Congratulations, works. I checked it:

  Reveal hidden contents

 

I suspect a kind of recursivity, but it probably will not show up for small n. For n=2 and n=3, the robot stays where it should,  which does not seem evident for larger n.

 

Edited by harey
Link to comment
Share on other sites

  • 0

For a 2x2 maze, the sequence will be Left- Right- Left

Let's assume our maze is 

a   b

c  d

The robot is standing at a, facing downward at c. As per the question, there will a path from a to d, so there could be cement on "b" or "c" or no cement at all. Also, there is cement outside the grid so the robot cannot move out of the grid.

Case1- Let's assume that the cement is in "b" and apply the commands- 

Left- The robot will turn towards "b" and hit the wall

Right- It will move towards "c" 

Left- It will move towards "d"- its destination

 

Case 2- Let's assume that cement is in "c" and apply the commands

Left- It will move towards "b"

Right- It will move towards "d"

Left- It will hit the cement outside the grid and will stay at the same place "d"

 

Case 3- Let's assume that there are no cement blocks

The movement will be same as in case 2

 

I hope this is acceptable as a solution

Link to comment
Share on other sites

  • 0

Was this a problem posed to a bunch of programmers? A solution for any 4x4 maze (although IDK whether or not this is an optimal one) is

  Reveal hidden contents

But when I tried running the algorithm to solve any 5x5 maze, it's been running for a while and still hasn't found a solution. I can't guarantee that this approach will find one. I'll paste the perl code below.

  Reveal hidden contents

 

Link to comment
Share on other sites

  • 0

It reached a final set of instructions for a 5 x 5 maze, which I'm sure you're all dying to see...

  Reveal hidden contents

This will work (unless my program is buggy), but I would be surprised if this is anywhere near optimal. And I'm not going to attempt a 10 x 10.

Link to comment
Share on other sites

  • 0

I changed the way the algorithm works, so that it more systematically checks all possible paths for all possible mazes and is guaranteed to eventually find the shortest possible set of instructions that will solve every maze of size n x n. The bad news is that it takes a long time to run. Even after doing what I could to make this run reasonably efficiently, it still could only process a 3 x 3 maze and will take a while to process even a 4 x 4 maze, albeit on a crummy laptop.

If this was a question posed to programmers, and the person asking the question knew full well that the numbers would get huge fast (checking all possible instructions for a 17 step solution would mean checking 417 = 17 billion potential solutions against almost 4000 mazes for the 4 x 4 case) and was making the point that you'll need to come up with something other than exhaustive brute force (sort of like the algorithm I had earlier but probably a smarter version), then it would make sense.

At any rate, this is a solution for any 3 x 3 maze with the shortest possible number of moves.

  Reveal hidden contents

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...