View Full Version : Resolved Labyrinth

11-14-2009, 02:43 AM
Let's say we let a hamster run in a 3-dimensional labyrinth.

The labyrinth has a certain number of chambers and a certain number of tunnels connecting the chambers. Each tunnel connects two chambers.

We let the hamster in from one end of the labyrinth and it must come out from the other one.

All the tunnels are one-way. Also, the chambers and tunnels are positioned, so that the hamster can never go back to a chamber it has already been to.

The program itself has to count how many possibilities the hamster has to get from the releasing chamber to the chamber with the exit from the labyrinth.

We know the number of the chambers and we know the number of the tunnels. Every chamber has a number, so the hamster starts from chamber number 1 and ends in the last (the highest) numbered chamber.

We also know the number data of the tunnels (from which chamber can the hamster move to which chamber).

For example:

Chambers: 5
Tunnels: 6

Tunnels (A to B):
1 -> 2
1 -> 3
3 -> 4
4 -> 5
2 -> 3
3 -> 5

What kind of guidelines should I follow while solving the problem?

Thank you in advance!

11-14-2009, 05:58 PM
This may be someone's homework assignment, but I wouldn't mind a hint too. I have tried for loops, 2d arrays, while loops, a function that looks for all possible combinations, but none do exactly like he is asking for.

It is really easy to figure out on paper, but for some reason this simple problem is stumping me when I try to write the code for it.

11-14-2009, 07:21 PM
Well, I found out the solution. It does in fact lay in 2-dimensional arrays.

The topic may be locked now :)