All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Wreck out! (Posted on 2006-04-03) Difficulty: 4 of 5
Supposing you are in a labyrinth, but you have a map and know where you are, there are many algorithms that will find a way out, if there is one.

Now, imagine you are allowed to wreck walls and make holes in them, so as to pass through. If you wreck enough walls, you are certain to be able to leave the labyrinth!

The problem: find an algorithm that determines the MINIMUM number of walls that should be broken in order to escape. Of course, it should also determine WHICH walls to break!

  Submitted by Federico Kereki    
Rating: 4.1429 (7 votes)
Solution: (Hide)
Letīs assume you know a standard way finder algorithm (SWFA) that finds a way from A to B, if there is one. Letīs also assume we have colors "1", "2", "3"... etc. The algorithm is as follows:

On the map, paint every place you can reach with the color "1"; If you painted the exit, then the SWFA will show you the way out, and youīre free!

Assuming you didnīt paint the exit, paint with color "2" every wall that could be breached from a place painted with "1"; if you painted the outside wall, applying the SWFA to reach from the outside wall to a "1" colored place, and again to get from there to the start, will get you out.

Assuming you havenīt excaped yet, paint with color "3" every place you can reach from a place painted with color "2"; if you painted the exit, apply the SWFA to reach from it to a "2" colored place, and again to get to a "1" colored place, and again to get to the starting place, and you are out!

Once again, if you didnīt paint the exit, paint with color "4" every wall that could be breached from a place painted with "3"... and so on; the algorithm is easily generalized.

If you used N colors, then int(N/2) walls had to be breached, and the way out is found by finding a path from color N to color N-1, then from there to color N-2, and so on until you get to the original spot.

Comments: ( You must be logged in to post comments.)
  Subject Author Date
SolutionMathematical thoughtsRobby Goetschalckx2006-04-04 04:03:08
SolutionHow I would do itTristan2006-04-04 02:01:26
SolutionSolutionBractals2006-04-03 14:47:02
SolutionI think I got it.Jer2006-04-03 13:24:26
Some ThoughtsMore thoughtse.g.2006-04-03 12:55:57
Some ThoughtsthoughtsBob Smith2006-04-03 12:00:05
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information