|
from me: Please leave some comments as they mean a lot <3.
Last day's puzzle was first solved by Konfustikator, while Pseudo_Utopia might be easier to understand.
+ Show Spoiler [solution] + Total color is 6, consider row_y which looks like row_y = {(0,y), (1,y), (2,y), ... (6,y)} clearly, row_y is a row with y axis value of y, and its x values ranges from 0 to 6. Since each row has 7 elements, then 2 of them must be the same color.
Now consider this area formed by {row_0, row_1, row_2, ... row_6^7}
This is a huge tall rectangle with height 6^7+1 and width 7. Since with 6 colors, all rows of 7 elements have 6^7 kinds of coloring scheme, then with a height of 6^7+1 two rows, say row_i, row_j must have identical coloring scheme.
Then since both row_i and row_j has 1 color that's repeated, that color will form the rectangle, whos verticies are identical color.
Considering draw out a picture if this is not intuitive enough, but this is a very clean solution.
Today's puzzle is a bit into the computer science side, but still fairly math oriented. It is as follows.
You have a maze, here is how it's constructed: the maze is made within a rectangular grid of size mxn, where m and n are arbitarily chosen natural numbers. Of any grid, it can either be part a path or a wall. From any point inside the maze, provided that it's not a wall, will have a way out. Then clearly, to walk outside of a maze, you'll have to go up, down, left, right in some way.
You also have a robot, here's the property of the robot: You can code the robot to move in a certain way. For instance, coding it with the sequence: left, left, up, up will make the robot attempt to move left twice, and up twice. If the robot is blocked on the left, executing the move "left" multiple times will not move the robot. The robot has no sense of perception, that is to say: -It cannot know if it hits a wall -It cannot know where it is inside the maze -It does not know how far it has walked
Your Job: Code the robot in such a way that for ANY valid maze [that is to say, for any m, n maze size and for any valid maze construction of that size] the robot will eventually be able to get out. The fine print: By ANY valid maze it means that regardless of size of m, n, and regardless of maze design, the robot will be able to move outside the maze eventually. That is to say, while you are coding, you cannot assume a certain m, n, or design.
Some example pictures:
Here is an example of a valid maze, with the maze area being black and white, and the outside area colored green. where the robot starts at the red point, and executing the instruction: up-up-down-down-right-right-left-left then ends up at point blue.
Again, post anything that comes across your mind, and if you're confident that you have the answer, put it in a spoiler. GL! Again, leave a comment, it'll be much appreciated and kept me doing these blogs.
Edit: No "random move" algorithms please.
   
|
Hmm. Left, down, right, up(times infinity) would ensure that our robot friend could always make progress, but if he gets caught in four open squares it wouldn't work. This is an interesting one, but I don't think I know enough to solve it. T_T
|
Far worse than that, even in the example with the red dot, LDRU repeated endlessly just results in it moving back and forth between the dot and the square below it.
My first thought on reading the question was "yay implement BFS ezpz" and then I got to the part where the robot can't sense anything. ;; Trying to think of some kind of psuedo-BFS (or more likely DFS in this case) I could implement without feedback.
|
I just noted that doing the Zig-Zag route up-right m*n times puts the robot in some "accumulation points" at corners. Im thinking about up-right m*n times then twisting the direction so the up-right becomes left-up. I think the brute force solution is some sort of up-right, left-up, down-left, right-down (each one m*n times) and then if you do the same again the robot ends up at the same square so you can do repeat but this time in other direction. Damn its hard to explain.
|
Spoilering in case I'm getting close to the answer, but I don't think I'm there yet.
+ Show Spoiler +Thinking about it more, psuedo-BFS may be the way to go after all. Because of the maze definition, there is some sequence of moves that will get the robot out. You could have it essentially attempt all possible combinations in a logical order (i.e. U; R; D; L; UU; UR; UD; UL; RU... etc.) that's easily written through loops, and do the inverse after each attempt (i.e. say it tries the sequence UDLRUDUDRR, the inverse would be LLUDUDLRUD) to attempt to return to the starting point, then start the next sequence. The problem with that is that since you have no feedback, performing the inverse sequence of moves is unlikely to return you to the starting position.
|
On June 08 2009 12:50 Macavenger wrote:Spoilering in case I'm getting close to the answer, but I don't think I'm there yet. + Show Spoiler +Thinking about it more, psuedo-BFS may be the way to go after all. Because of the maze definition, there is some sequence of moves that will get the robot out. You could have it essentially attempt all possible combinations in a logical order (i.e. U; R; D; L; UU; UR; UD; UL; RU... etc.) that's easily written through loops, and do the inverse after each attempt (i.e. say it tries the sequence UDLRUDUDRR, the inverse would be LLUDUDLRUD) to attempt to return to the starting point, then start the next sequence. The problem with that is that since you have no feedback, performing the inverse sequence of moves is unlikely to return you to the starting position.
You can't do inverse. For instance, say your robot has a wall on the immediate left. The sequence LLL will be inversed to RRR, yet LLLRRR will certainly NOT make you go back to the original point.
|
For Malongo:
+ Show Spoiler +I looked at a couple of approaches very similar to that, and I don't think it quite works. Running some test cases on the example provided, the collection points can end up not being anywhere near the exit, and having no direct path between any collection point and the exit. If you got lucky and tried R-D followed by L-D immediately from the start, you'd get it, but you can't assume that kind of luck, and the starting position shown is not actually a collection point itself, so you can't really get back to it. Unless there's some way of juggling the order of attempts I haven't thought of, I don't think what you have is going to reliably produce a solution.
|
On June 08 2009 12:54 evanthebouncy! wrote:Show nested quote +On June 08 2009 12:50 Macavenger wrote:Spoilering in case I'm getting close to the answer, but I don't think I'm there yet. + Show Spoiler +Thinking about it more, psuedo-BFS may be the way to go after all. Because of the maze definition, there is some sequence of moves that will get the robot out. You could have it essentially attempt all possible combinations in a logical order (i.e. U; R; D; L; UU; UR; UD; UL; RU... etc.) that's easily written through loops, and do the inverse after each attempt (i.e. say it tries the sequence UDLRUDUDRR, the inverse would be LLUDUDLRUD) to attempt to return to the starting point, then start the next sequence. The problem with that is that since you have no feedback, performing the inverse sequence of moves is unlikely to return you to the starting position. You can't do inverse. For instance, say your robot has a wall on the immediate left. The sequence LLL will be inversed to RRR, yet LLLRRR will certainly NOT make you go back to the original point. I said that in my explanation It's why I said I didn't think I had it yet.
|
randomly choose the direction. even if it takes ages, at some point you will get out :o
|
On June 08 2009 12:56 Macavenger wrote:Show nested quote +On June 08 2009 12:54 evanthebouncy! wrote:On June 08 2009 12:50 Macavenger wrote:Spoilering in case I'm getting close to the answer, but I don't think I'm there yet. + Show Spoiler +Thinking about it more, psuedo-BFS may be the way to go after all. Because of the maze definition, there is some sequence of moves that will get the robot out. You could have it essentially attempt all possible combinations in a logical order (i.e. U; R; D; L; UU; UR; UD; UL; RU... etc.) that's easily written through loops, and do the inverse after each attempt (i.e. say it tries the sequence UDLRUDUDRR, the inverse would be LLUDUDLRUD) to attempt to return to the starting point, then start the next sequence. The problem with that is that since you have no feedback, performing the inverse sequence of moves is unlikely to return you to the starting position. You can't do inverse. For instance, say your robot has a wall on the immediate left. The sequence LLL will be inversed to RRR, yet LLLRRR will certainly NOT make you go back to the original point. I said that in my explanation  It's why I said I didn't think I had it yet. HAHHA i read everything but your last sentence. >_<
|
+ Show Spoiler +Also, you might want to revise the question a wee bit, since I think technically if you just tell the robot to choose a random direction at each move, statistically it will get out eventually... but I don't think that's really in the spirit of the problem.
|
+ Show Spoiler +loop LU * i, RU * i, RD * i, LD * i with i increasing every cycle from 1 to max(m,n) and reset i to 1 when if it reaches the upper boundary.
I guess you can trap this as well but I'm too tired to think properly :o
|
On June 08 2009 13:14 ven_ wrote:+ Show Spoiler +loop LU * i, RU * i, RD * i, LD * i with i increasing every cycle from 1 to max(m,n) and reset i to 1 when if it reaches the upper boundary.
I guess you can trap this as well but I'm too tired to think properly :o It does not know what is a boundry.
|
On June 08 2009 13:04 Macavenger wrote: Also, you might want to revise the question a wee bit, since I think technically if you just tell the robot to choose a random direction at each move, statistically it will get out eventually... but I don't think that's really in the spirit of the problem. done
|
On June 08 2009 13:16 evanthebouncy! wrote:Show nested quote +On June 08 2009 13:14 ven_ wrote:+ Show Spoiler +loop LU * i, RU * i, RD * i, LD * i with i increasing every cycle from 1 to max(m,n) and reset i to 1 when if it reaches the upper boundary.
I guess you can trap this as well but I'm too tired to think properly :o It does not know what is a boundry. Well, the algorithm does. I'm referring to i reaching max(m,n).
|
On June 08 2009 13:20 ven_ wrote:Show nested quote +On June 08 2009 13:16 evanthebouncy! wrote:On June 08 2009 13:14 ven_ wrote:+ Show Spoiler +loop LU * i, RU * i, RD * i, LD * i with i increasing every cycle from 1 to max(m,n) and reset i to 1 when if it reaches the upper boundary.
I guess you can trap this as well but I'm too tired to think properly :o It does not know what is a boundry. Well, the algorithm does. I'm referring to i reaching max(m,n). Ah I should probably fix it... By "Arbitary" I mean the algorithm provider does not know the size of m and n... I'll go fix it now. Thx.
|
Pretty easy.
+ Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
|
On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
You don't know where the walls are.
|
On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
Too technical, i have no clue what you just said. just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall.
|
On June 08 2009 13:32 evanthebouncy! wrote:Show nested quote +On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
Too technical, i have no clue what you just said. just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall. + Show Spoiler +It's been a couple years since I worked with Turning machines and non-determinism, so I'm a bit rusty, but reading his solution, I'm quite certain it correctly proves the existence of an algorithm. Non-deterministic Turing Machines can do some pretty interesting things, and can easily have paths that lead nowhere, which would be the equivalent of attempting to move into a wall.
|
On June 08 2009 13:32 evanthebouncy! wrote:Show nested quote +On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
Too technical, i have no clue what you just said. just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall.
You said it's more or less computer science. This is really standard stuffs. In fact I am not even a computer scientist and I know it.
EDIT:
just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall. That is irrevalent. So long as there is one possible path for an exit in finite time non-deterministic turing machine will give a pass. Try wiki on turing machines first.
|
Alright... I don't have anything yet, but a few observations are:
The sequence has to include up, right, left, and down, otherwise you can be trapped.
There has to be net motion in one direction in the case of a 1000x1000 maze with no walls or something.
Up, right, left, down does not work. In other words, you need multiple moves to up, right, left, down in some sequence?
If this is something I had no chance of getting in the first place, I would be pretty sad. It's midnight, so I'm going to try again tomorrow.
|
On June 08 2009 13:37 illu wrote:Show nested quote +On June 08 2009 13:32 evanthebouncy! wrote:On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
Too technical, i have no clue what you just said. just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall. You said it's more or less computer science. This is really standard stuffs. In fact I am not even a computer scientist and I know it. I c, lemme do some search on it.
|
On June 08 2009 13:37 Macavenger wrote:Show nested quote +On June 08 2009 13:32 evanthebouncy! wrote:On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
Too technical, i have no clue what you just said. just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall. + Show Spoiler +It's been a couple years since I worked with Turning machines and non-determinism, so I'm a bit rusty, but reading his solution, I'm quite certain it correctly proves the existence of an algorithm. Non-deterministic Turing Machines can do some pretty interesting things, and can easily have paths that lead nowhere, which would be the equivalent of attempting to move into a wall. His approach doesn't work. He can't move into a direction that isn't a wall because he doesn't know where they are. Even if he knew where the walls were it wouldn't be much different from a NDTM that moved into any direction at all and it would accept. This is nothing else than using a random direction every step.
|
On June 08 2009 13:46 ven_ wrote:Show nested quote +On June 08 2009 13:37 Macavenger wrote:On June 08 2009 13:32 evanthebouncy! wrote:On June 08 2009 13:27 illu wrote:Pretty easy. + Show Spoiler + Since at any point there is one way out, we can create a non-deterministic Turing Machine as follows:
1. At each position, move to any of the other possible positions that are not walls.
Then this Turing Machine will always accept, by construction of the maze. We know that non-determinism gives no extra computation powers so we can come up with an algorithm by a Turing Machine to create this path, which executes on finite time.
The actual algorithm is extremely simple so I won't get too detailed in this. (wiki if you like). Just go with a breadth-first search and you will get a path that allows you to exit. As shown before this algorithm will complete on finite time which is what we want.
Too technical, i have no clue what you just said. just reading your (1) though: you cannot garentee that you "moved" in a sense that the robot does not know if its attempted move is not blocked by the wall. + Show Spoiler +It's been a couple years since I worked with Turning machines and non-determinism, so I'm a bit rusty, but reading his solution, I'm quite certain it correctly proves the existence of an algorithm. Non-deterministic Turing Machines can do some pretty interesting things, and can easily have paths that lead nowhere, which would be the equivalent of attempting to move into a wall. His approach doesn't work. He can't move into a direction that isn't a wall because he doesn't know where they are. Even if he knew where the walls were it wouldn't be much different from a NDTM that moves into any direction at all and it would accept. This is nothing else than using a random direction every step.
But there is always one way to exit, so when we expand our tree diagram we will have one accepting state somewhere. So I think my NDTM will accept any solvable mazes.
|
ven brings up a good point that it might be equivalent to a random solution, though.
Need to be less rusty, argh D:
|
That's not the issue. Your turing machine would work with information that it doesn't have (where the walls are). Also as far as I understand the question we have to provide a deterministic algorithm to solve the maze which your non-deterministic TM doesn't do. :o
|
Alright. This came to me while I was lying awake. I haven't thought too deeply about it, and I haven't even bothered to check it, but something like this:
+ Show Spoiler +Okay. This is a bit hard to put in words. First: move along the "x-axis" the maximum number of times that you can + 1. Second, move along the "y-axis" the maximum number of times that you can in the maze + 1. Then use the same process reversing the directions along both axes. (For instance, in a 100x100 maze, you would move right 101 times first, and then move down 101 times, or move left 101 times and then down 101 times, or whatever. Thus, you can exit the maze if it's "blank")
Now, this should allow you to end up going directly to the furthest possible space "To the left" or "upwards". Now the problem that I saw was that you can end up in a shape where the robot can move 50 times left, 0 times upward, 50 times right, 0 times downward- if he gets stuck in two shapes like [ and ].
To counter that, inject a random single move in any direction between every two long moves.
Even if this isn't it, hopefully I'm at least on to something.
|
On June 08 2009 14:10 Zozma wrote:Alright. This came to me while I was lying awake. I haven't thought too deeply about it, and I haven't even bothered to check it, but something like this: + Show Spoiler +Okay. This is a bit hard to put in words. First: move along the "x-axis" the maximum number of times that you can + 1. Second, move along the "y-axis" the maximum number of times that you can in the maze + 1. Then use the same process reversing the directions along both axes. Now, this should allow you to end up going directly to the furthest possible space "To the left" or "upwards". Now the problem that I saw was that you can end up in a shape like
[ r ]
R is the robot. He moves left 50 times or something, moves up forty times, and then moves right 50 times: an infinite loop.
To counter that, inject a random single move in any direction between every two long moves. Even if this isn't it, hopefully I'm at least on to something. You don't know the maximum number. I had a similar idea but without knowing how many times you can move you wouldn't know when to stop.
|
+ Show Spoiler +Yeah you do... Because the grid is only MxN, you can just use those numbers, right? If he runs into a wall, it's all good, he'll just stop there and continue going eventually in the next direction.
|
On June 08 2009 12:05 evanthebouncy! wrote: The fine print: By ANY valid maze it means that regardless of size of m, n, and regardless of maze design, the robot will be able to move outside the maze eventually. That is to say, while you are coding, you cannot assume a certain m, n, or design.
|
Yeah, not knowing m and n for the given maze really makes this more challenging. The only direction I can think to go with it at this point is some kind of spiraling thing, where you loop from 1 to k steps in each direction, then from k to 1, then increment k and repeat. Then you have to come up with some kind of crazy reordering of directions you're trying to avoid the collection points trap we were discussing early, I would think.
|
Yeah, I had the same idea of spiraling movement in my mind. Those pesky walls totally disrupting it of course :p
|
+ Show Spoiler +Suppose we are given the maze but not the starting position. Then we can solve the puzzle by looking at each possible starting position in turn. In short, we pick some box and assume the robot started there, giving it commands to solve the puzzle. Then, we pick a second box to assume the robot started in, see where the robot would be after our commands based on the first assumption, and give it commands to exit the maze. Etc.
Since the set of possible mazes is countable, we can adjoin the solutions for every given maze end to end and be done.
|
Now I doubt that within finite steps the solution can be achieved...
The spiral path may be promising solution, if there exsits a solution.
|
On June 08 2009 14:13 ven_ wrote:Show nested quote +On June 08 2009 14:10 Zozma wrote:Alright. This came to me while I was lying awake. I haven't thought too deeply about it, and I haven't even bothered to check it, but something like this: + Show Spoiler +Okay. This is a bit hard to put in words. First: move along the "x-axis" the maximum number of times that you can + 1. Second, move along the "y-axis" the maximum number of times that you can in the maze + 1. Then use the same process reversing the directions along both axes. Now, this should allow you to end up going directly to the furthest possible space "To the left" or "upwards". Now the problem that I saw was that you can end up in a shape like
[ r ]
R is the robot. He moves left 50 times or something, moves up forty times, and then moves right 50 times: an infinite loop.
To counter that, inject a random single move in any direction between every two long moves. Even if this isn't it, hopefully I'm at least on to something. You don't know the maximum number. I had a similar idea but without knowing how many times you can move you wouldn't know when to stop.
You don't have to know the maximum number. If you could guarantee that you had an algorithm capable of solving it for a given width/height you could run some loops varying the width height, increasing the maximum number the width and height can take each run through and then running the algorithm for those values. You would have to cover all of the possible width height combinations until you actually get to the real width/height.
|
On June 08 2009 15:06 moriya wrote: Now I doubt that within finite steps the solution can be achieved...
The spiral path may be promising solution, if there exsits a solution.
Muirhead solved it.
|
sure hope the op has an answer not just a trick question that has no answer to it
|
On June 08 2009 16:18 omG.[RaYnE] wrote:sure hope the op has an answer not just a trick question that has no answer to it 
evan's questions are always legit. Most of them are difficult(to me at least), but all of them have "real" answers.
|
+ Show Spoiler +easy. bruteforce this shit. put your instructions in a dynamic array. Go through all the possibilities of instructions for the current size of the the array. ++the size of the array and you'll have it... eventually.
|
To those of you who gave generic CS solutions (be it greedy, breadth-depth search, etc.), it doesn't work because you don't know the "exit condition" because the robot doesn't know when it has hit a wall and could not move further. Your program will most likely result in an infinite loop.
|
On June 08 2009 18:57 Cambium wrote: To those of you who gave generic CS solutions (be it greedy, breadth-depth search, etc.), it doesn't work because you don't know the "exit condition" because the robot doesn't know when it has hit a wall and could not move further. Your program will most likely result in an infinite loop. well then its going to do that anyways. I'm sure I could do the math to figure out the limit I need for my solution but I really am to lazy. Programmers are lazy dudes. No one would ever program anything without an exit condition. Even if you found a correct solution you would never know when you hit the exit. So you would keep going and going. The robot can't know where it is. I therefor assume that the robot will exit automatically when I have reached my destination.
|
+ Show Spoiler + I'll have a go at this.
Result 1: Given any two start position in a fixed maze and two robots on one each, there exists a finite instruction such that, when executed simultaneously by the two robots (and no collision between the robots, so they are like probes on mining mode), they will eventually stack.
Assume the contrary. Find two starting positions with the minimal shortest path (ie, for each pair calculate the shorest path, then find the pair with the minimal value) such that the above fails. Call the two squares A and B and put robots there. Say the Euclidean (ie, measure with ruler distance) distance between them currently be say, d.
Now let the robot at A move towards B using the shortest path and let the other robot replicate the moves. The shortest path between robots does not increase during this whole time since one robot is reducing it. The shortest path also does not decrease by our minimal assumption. When the first robot gets up to position B, let the other be at position C. Now the path looks just like the original, because as one robot was "erasing" the path, the other one was "tracing" an identical one. Hence the Vector BC = Vector AB. And C is now 2d distance away from A.
We can continue this process and yield points D, E, F etc which gets further away from A by d each time. This is a contradiction since our maze is finite.
Result 2: Given a fixed maze and a robot on each square of the maze, there exists a finite instruction such that, when executed simultaneously by all robots, they will all stack.
This follows directly from Result 1. We just pick out any two separated robots, use Result 1 to stack them. Since once stacked they don't unstack, we can just pretend they are one robot. Repeat until all robots are stacked.
For a particular maze, define the sequence of moves found in Result 2 the "imba sequence"
Now after performing the "imba sequence", say the stacked robots are on a square S (which only depends on the "imba sequence" and not the start points). For any other square T, we can just now 1a2a3a our stacked robots there. Call this sequence of moves "attack-T sequence".
Final Result: Define our algorithm as follows:
List out all possible strings made up of U,D,L,R of length k, for all k. Concatenate them all together (so list all the possible strings of length 1, then 2, then 3 etc). It's clear that this big string has countable length. We'll prove that this algorithm satisfies the problem.
For any square T on the maze, combine our "imba sequence" with our "attack-T sequence", call it "bisu sequence" or something. Clearly the sequence is finite, so it appears in our algorithm somewhere. Consider performing the algorithm up to the start of "bisu sequence". Now no matter where the robot is, the "bisu sequence" will bring it to square T. And since this works for any T, no matter where the end of the maze is, as long as it's finite, the robot will get there in finite number of moves.
Hopefully it is correct :-).
Edit: Just read Muirhead's, It's much shorter/nicer :-). At least this is different and has a few additional results.
|
+ Show Spoiler +Start with a length of 1. Follow every possible sequence with that length. Increase length by 1. Repeat.
Example: U, R, D, L, (length+1), UU UR UD UL, (length+1), UUU, UUR, UUD, UUL, URU, URR, URD, URL, UDU, UDR, UDD, UDL, ULU, ULR, ULD, ULL, (length+1), etc..
This way we'll create every possible path through the maze. It doesn't matter that we change positions between the tries because for every position there is a solution and as soon as our path is long enough we will eventually find the exit path that matches our current position.
This would be easier if we had knowledge about the maze size because we could just always use the longest possible path for our length but since we don't have that we increase our path length until we reach the one that we need.
|
On June 08 2009 23:49 ven_ wrote: Start with a length of 1. Follow every possible sequence with that length. Increase length by 1. Repeat.
Example: U, R, D, L, (length+1), UU UR UD UL, (length+1), UUU, UUR, UUD, UUL, URU, URR, URD, URL, UDU, UDR, UDD, UDL, ULU, ULR, ULD, ULL, (length+1), etc..
This way we'll create every possible path through the maze. It doesn't matter that we change positions between the tries because for every position there is a solution and as soon as our path is long enough we will eventually find the exit path that matches our current position.
This would be easier if we had knowledge about the maze size because we could just always use the longest possible path for our length but since we don't have that we increase our path length until we reach the one that we need.
There is a problem with your assumptions. That it doesn't matter that we change positions is incorrect for example consider the length of three. It is possible that after doing UUU, UUR, UUD, that you moved to a spot such that UUU is the correct way to exit but you won't do that sequence again since you already did it in your rotation. The way to fix that would be to have every permutation of sequences for each length. Thus for every length i you would have (4^i)! sequences of lengths i. The total sum of moves in this sequence passes 1 mil within just like 5-6 lengths. Therefore a random algorithm would be loads better. I seriously don't understand why you are disallowing that.
|
I do say that it will follow every possible arrangement of sequences for each length. So it will repeat ifself again. It will in fact repeat every previously used sequence 4 times per increase in length.
|
You missed what I'm saying completly.
You have every possible sequence of moves of length 3 as per what you said. But what I'm saying is that there are 4^3 such sequences and that you need to have every such possible arrangment of those sequences in order to fix the problem of not knowing where you are.
You need to write every permutation of these 4^3 sequences or (4^3)! sequences of length 3.
I'm saying that you stop at 4^3 and you need (4^3)!.
|
No, I don't stop anywhere. The length will increase indefinitely. The example only shows the first 3 steps in order to show how it works. It doesn't stop there.
|
no i know that you continue past 3. I'm saying that you to have your step for each length be longer.
|
Such a solution tells nothing about the core of questions... I thought the original question is to ask a gernal solution for every possible box. For example, in 1D case the solution is UDDUUUDDDDUUUUU...How to prove that there is no such a sequence for 2D case?
On June 08 2009 16:09 evandi wrote:Show nested quote +On June 08 2009 15:06 moriya wrote: Now I doubt that within finite steps the solution can be achieved...
The spiral path may be promising solution, if there exsits a solution. Muirhead solved it.
|
My solution is exactly the equivalent of UDDUUUDDDDUUUUU... in the 1-dimensional case. I provide a single sequence which solves every possible maze.
All solutions posted are either like mine and Ivs's, grossly inefficient but nicely deterministic, or they are based on randomness. The random solutions are in many senses nicer but are "only" guaranteed to succeed with probability 1. Which you prefer depends on whether you want to be a practical computer scientists or an AWESOME MATHEMATICIAN ^^.
Though to be honest, I don't know enough (any) comp sci. Could someone summarize how fast my algorithm runs compared to a random algorithm?
|
You didn't really provide any actual algorithm. But even then, any algorithm to solve a maze of this kind would be so horribly inefficient and slow that it doesn't make sense to compare their runtime.
|
Sure I provided an actual algorithm
|
I don't think it is obvious that
On June 08 2009 23:49 ven_ wrote:+ Show Spoiler + This way we'll create every possible path through the maze. It doesn't matter that we change positions between the tries because for every position there is a solution and as soon as our path is long enough we will eventually find the exit path that matches our current position.
Every possible path does occur, but you haven't shown that upon the positional change, the right path will follow.
For example, considers two squares A and B, let the classes of sequences that finish the maze be c(A) and c(B). Each member c(A) and c(B) does occur infinitely often, but you could have say, each element of c(B) only follows position A and each of c(A) only follows position B. To complete it you would need to show that the sets c(A) and c(B) have common elements, which they in fact do.
|
@ Muirhead: I know that this problem doesn't specify it, but generally, robots should be constrained by processing ability and memory. Keeping an enumeration of 2^{m*n} possible mazes should be out of the question. As a math solution, this would work, but I don't think the quantifiers of the problem were set up as well as they could have been.
That being said, I believe some variant of bugnav should do the trick.
|
Hrm I'm pretty sure that to execute my solution the robot would only need to keep one maze in its head at a time, though it would need to remember a set of directions corresponding to every square on the maze.
|
On June 08 2009 14:44 Muirhead wrote:+ Show Spoiler +Suppose we are given the maze but not the starting position. Then we can solve the puzzle by looking at each possible starting position in turn. In short, we pick some box and assume the robot started there, giving it commands to solve the puzzle. Then, we pick a second box to assume the robot started in, see where the robot would be after our commands based on the first assumption, and give it commands to exit the maze. Etc.
Since the set of possible mazes is countable, we can adjoin the solutions for every given maze end to end and be done.
Interesting that you can try exhaustively on all mazes without worrying where the previous maze left your robit, since you are guessing from an unknown starting location. Counter intuitive, but cool once you think about it.
Worst-case runtime: + Show Spoiler + Let B be the enumeration of possible mazes. This isn't exactly 2 ^ (m x n), since any open square must lead to an exit, but it is O(2 ^ (m x n)). To prove this, consider all mazes that do not have a solution path and are therefore invalid. Now make every other row entire open. All previously-invalid open squares are now adjacent to a solution row, while preserving (m x n) / 2 of the cells.
For every board there are O(m x n) starting positions to try. Since you know which board you are currently trying, there exists a known solution path of length O(m x n). So we immediately know that it will require O(B x m^2 x n^2) moves.
I'll work on non-deterministic runtime and expected runtime in a bit.
|
I thought the maze was supposed to be arbitrary?
Solutions to this (assuming maze is given) seem inefficient like ven_ said. Assuming we follow an algorithm like muirhead's (can't really think of another solution, his is pretty cool)
Worst case the last box you check would be the correct box. Obvious upper bound for boxes are O(m^2 * n^2). Number of boxes to check would be O(m^2 * n^2). Of course you likely could math it down to a better upper bound.
Something similar to ...
loop1 : i = 1.. m^2 * n^2 //ith box you check loop2: j = 1 .. i //follow 1..ith path m^2*n^2 instructions //follow the path
Not sure if my math is right (not going to bother thinking too much, at work), but you get something like an arithmetic series 1+2+3+...+k, where k is m^2 * n^2. We know that the 1+2+...k is O(k^2), so you get O(m^4 n^4), but then this is assuming one instruction. We have at most m^2n^2 instructions so you get m^6n^6.
O(m^6n^6) + finding paths for all boxes (which seems like it'll be easier to do).
|
On June 10 2009 02:32 Daveed wrote: @ Muirhead: I know that this problem doesn't specify it, but generally, robots should be constrained by processing ability and memory. Keeping an enumeration of 2^{m*n} possible mazes should be out of the question. As a math solution, this would work, but I don't think the quantifiers of the problem were set up as well as they could have been.
That being said, I believe some variant of bugnav should do the trick.
Most bug pathfinders are based on some limited information about the map. Our robit cannot detect collisions (or anything for that matter), so wall-crawling, tangent bug, etc. are simply out of the question. Because we have no information, the problem lends itself to non-heuristic approach.
As for memory constraints, you require (m x n) bits to store any one maze. Generating another is simply a matter of incrementing bits until you have exhausted all permutations. For any given maze, I believe that you can construct a spanning tree of the adjacency matrix in O(m x n) time. You can search the tree for a solution (not necessarily the shortest) from any starting location in just as much time (linear).
Computationally, 2 ^ (m x n) is bad, but you really cannot avoid this part of the problem. At best, you can do a depth-first approach and compute massively in parallel.
|
@Muirhead: Although it needs to keep only one maze in its head at a time, it also needs to know which maze it's on, in order to generate the next maze in its enumeration (that IS what you are doing, correct?).
@ mmp: I had overlooked the inability of the robot to detect where it was. Sure, point taken.
|
On June 10 2009 05:08 Daveed wrote: @Muirhead: Although it needs to keep only one maze in its head at a time, it also needs to know which maze it's on, in order to generate the next maze in its enumeration (that IS what you are doing, correct?).
I wrote: As for memory constraints, you require (m x n) bits to store any one maze.
That should read, (m x n) bits to keep track of the maze you are on. Simply increment the bits to look at the next maze. The information encoding IS the structure it represents (let every 1 be a wall, 0 non-wall).
|
|
|
|
|