I go on random bike rides. I go down my driveway, and then at each choice point I flip
a coin: Heads means to choose the leftmost road, Tails means to choose the rightmost. If there are 3 choices at
the intersection, I flip twice: Heads Heads means to take the leftmost, Heads Tails means to choose
the middle road, Tails Heads means choose the rightmost, and Tails Tails is a "do-over" -- repeat the
whole process until a choice is made.
The ride continues until the random ride leads me back up my driveway to my house.
Here is a map of my neighborhood. All of the intersections where a choice can be
made are shown with a capital letter and my home is marked "Home".
+-----M-----N----------+
| | | |
I-----J-----K----------L
| | | |
+-----G-----H | |
| | | | |
+-----B-----C-----D-----E---+ |
| | |
Home ---------A +------F
| |
| |
+----------------------------------+
Instead of actually flipping a coin while riding my bike, I record the results of
a sequence of flips to use during the ride. If during my ride I use them all then I start back at the
begining of the sequence. Given flips return the number of flips needed to get me
back home. If I never will get back home, return -1.
|