Drunkard's Journey Home
In this challenge you are to write a program which simulates a drunkard stumbling his way home from the bar.
The input will be an adjacency matrix (representing a directed graph) which represents paths the drunkard can take. At each location, the drunkard will choose one path at random (Each option has an approximately equal chance and is independent of prior choices) to follow.
Assume that the drunkard always starts at the bar (first row in the adjacency matrix).
If the drunkard enters a dead-end it can be assumed that he has either made his way home or has been arrested for public intoxication and the program should return his path.
It can be assumed that the graph will always contain at least one dead-end.
It can also be assumed that the drunkard will always be able to exit the bar (the first row will not be all zeroes) and that if the drunkard would be stuck in a location, that the row would be represented by all zeroes.
The output will be the path the drunkard took in his attempt to make his way home. The values for the locations can be either zero or one indexed.
Input [1,0,1,1] [0,0,0,0] [1,0,0,0] [1,1,1,1] Possible Outputs [0,2,0,3,2,0,0,3,1] [0,3,0,3,1] Input [0,1,1,1,0,1] [1,0,1,0,1,1] [0,0,0,0,0,0] [0,0,0,0,0,1] [1,0,0,0,0,0] [0,0,0,0,0,0] Possible outputs [0,1,5] [0,5] [0,1,4,0,2] [0,3,5] [0,3,0,1,4,0,5] Deterministic path: Input [0,0,1,0] [0,0,0,1] [0,1,0,0] [0,0,0,0] Output [0,2,1,3]