Microsoft Interview Question
Software Engineer / Developersvoid createMaze(int x1, int x2, int y1, int y2)
{
if(x2-x1>1 && y2-y1>1)
{
randX=random(x1,x2);//num between x1 and x2(excluding x1 and x2)
randY=random(y1,y2);
line(randX, y1, randX, y2);
line(x1, randY, x2, randY);
//now you have 4 lines(2 intersected)
//you have to reach from one end to another
//so make 1 gap at random position on 3 of the line
//(1 gap for each line)
make3Gaps();
createMaze(x1, y1, randX, randY);
createMaze(randX, y1, x2, randY);
createMaze(x1, randY, randX, y2);
createMaze(randX, randY, x2, y2);
}
}
a deatiled approach is provided here bittyjava.wordpress.com/tag/book/
- Anonymous July 08, 2007