Jump to content


Welcome to BrainDen.com - Brain Teasers Forum

Welcome to BrainDen.com - Brain Teasers Forum. Like most online communities you must register to post in our community, but don't worry this is a simple free process. To be a part of BrainDen Forums you may create a new account or sign in if you already have an account.
As a member you could start new topics, reply to others, subscribe to topics/forums to get automatic updates, get your own profile and make new friends.

Of course, you can also enjoy our collection of amazing optical illusions and cool math games.

If you like our site, you may support us by simply clicking Google "+1" or Facebook "Like" buttons at the top.
If you have a website, we would appreciate a little link to BrainDen.

Thanks and enjoy the Den :-)
Guest Message by DevFuse
 

Photo
- - - - -


  • Please log in to reply
11 replies to this topic

#1 psychic_mind

psychic_mind

    Advanced Member

  • Members
  • PipPipPip
  • 321 posts

Posted 15 August 2010 - 01:47 PM

There doesn't appear to be many algorithm puzzles on this forum, so I thought I would start some and see how they are received.

You are given an n x m matrix/array of 1s and 0s. You are given starting co-ordinates (A,B) and destination co-ordinates (X,Y). Your goal is to find the quickest path to get from start to finish moving 1 square at a time (no diagonals). However, you cannot move onto a square with a 1 in it. Effectively you have to solve a maze. The output should give directions and be something of the form:

UUDDLRLUUD

You can use this as a test case:

m=10
n=10
A=0
B=0
X=9
Y=9

Maze {
0,1,0,0,0,1,0,0,0,0,
0,0,0,1,0,0,0,1,1,0,
0,1,1,1,1,1,1,1,0,0,
0,1,0,0,0,0,0,1,0,1,
0,1,0,1,1,1,0,1,0,1,
0,1,0,0,0,1,0,1,0,0,
0,1,1,1,0,1,0,1,1,0,
0,1,0,0,0,1,0,1,0,0,
0,1,0,1,1,1,0,1,0,1,
0,0,0,0,0,0,0,1,0,0
}
The most time efficient algorithm will be the winner (credit may also be given to the most memory efficient solution). Good Luck. :)

Edited by psychic_mind, 15 August 2010 - 01:48 PM.

  • 0

#2 qwe qwe

qwe qwe

    Advanced Member

  • Members
  • PipPipPip
  • 418 posts

Posted 15 August 2010 - 02:10 PM

Spoiler for suggestion, not solution

  • 0

#3 krityx

krityx

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 15 August 2010 - 04:28 PM

sorry double post.

Edited by krityx, 15 August 2010 - 04:30 PM.

  • 0

#4 krityx

krityx

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 15 August 2010 - 04:30 PM

Spoiler for idea

  • 0

#5 qwe qwe

qwe qwe

    Advanced Member

  • Members
  • PipPipPip
  • 418 posts

Posted 15 August 2010 - 08:47 PM

Spoiler for idea


Ingenious, I like that idea...
  • 0

#6 K4D

K4D

    Junior Member

  • Members
  • PipPip
  • 90 posts

Posted 15 August 2010 - 10:03 PM

Spoiler for

  • 0

#7 fedorocker

fedorocker

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 16 August 2010 - 05:45 AM

Spoiler for idea


I was thinking that a little variation of this algorithm should work better. We could apply the algo. with two start points : the starting point(with every successive no. on the +ve scale i.e. 2,3,4,...) and the destination point(with every successive path unit getting a no. on the negative scale -2,-3,-4,...). This will first of all ensure that there exists an entry into the destination. The algo. will then stop as soon as a positive no. (obviously >1) is found besides a negative one. Also in case of multiple such paths, it is highly likely that we always get the shortest path.
  • 0

#8 DeeGee

DeeGee

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts

Posted 16 August 2010 - 10:13 AM

Spoiler for I think


Spoiler for Just realised

Edited by DeeGee, 16 August 2010 - 10:17 AM.

  • 0

#9 psychic_mind

psychic_mind

    Advanced Member

  • Members
  • PipPipPip
  • 321 posts

Posted 16 August 2010 - 10:32 AM

I think the correct solution has been found by krityx and implemented K4D. The algorithm should only have linear time complexity for a maze with N squares. Now I need to see if I something else for Algorithm 2!
  • 0

#10 qwe qwe

qwe qwe

    Advanced Member

  • Members
  • PipPipPip
  • 418 posts

Posted 16 August 2010 - 02:29 PM

I think the correct solution has been found by krityx and implemented K4D. The algorithm should only have linear time complexity for a maze with N squares. Now I need to see if I something else for Algorithm 2!


In case you didn't get the VM I sent you, go check out the "Other Mind Boggling Stuff on the Web" forum...:)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users