I recently came across a (very simple) high school probability problem which simply asked for the probability that the robot described below falls off the cliff after exactly 5 steps with $p$ specified. I'm more interested in the random variable implied in that problem than this specific case, which can be calculated by simply following the relevant branches in a tree. To put the problem that I am interested in into words:
Problem
A robot stands at the edge of a cliff and continues taking fixed-sized steps either towards the cliff with probability $p$ or away from the cliff (with probability $1-p$) until it falls over the edge.
Let's define a random variable $X$ as the number of steps the robot takes before it falls over the edge of the cliff.
What is the probability mass function of $X$?
Here are my thoughts so far.
In order for the robot to walk off the cliff, it must take $n$ steps away from the edge and $n+1$ towards the edge. This rules out the possibility of the robot falling over the edge after an even number of steps. Further (for an odd number of steps) it suggests that the probability that the robot walks off the cliff may be expressed in the form $C \cdot p^{n+1}\cdot (1-p)^{n}$ where $2n+1=x$ is the total number of steps, and $C$ is some coefficient to be determined.
I'm assuming that, given an eternity, the robot must at some point fall off the cliff (an assumption that niggles me a little), but that there is no upper bound on the number of steps that it will take.
The last step must, of course, be the step that takes the robot over the edge. Further, none of the preceding steps can take the robot over the edge in the meantime. (This prevents us from using a binomial distribution to model the situation.)
If $p<0.5$ the robot tends to get further away from the cliff as time goes by and the characteristic values of $X$ grow astronomically. Even with $p=0.5$, computer simulations show that some very large values of $x$ do sometimes occur in a moderate number of simulations. For $p$ even slightly below $0.5$ the computer hangs (as expected) for even a moderate number of simulations.
In addition to playing around with simulations, I have got the computer to start off with a binomial tree associated with $x$ steps and to then lop off any branches that do not meet the criteria specified above so that I can see some sample values of $C$, the coefficient described above. Below is a sample of the output along with the successful sequences of steps; A stands for a step away from the cliff, T for a step towards the cliff.
Steps: 1
Coefficient: 1
T
Steps: 3
Coefficient: 1
ATT
Steps: 5
Coefficient: 2
AATTT
ATATT
Steps: 7
Coefficient: 5
AAATTTT
AATATTT
AATTATT
ATAATTT
ATATATT
Steps: 9
Coefficient: 14
AAAATTTTT
AAATATTTT
AAATTATTT
AAATTTATT
AATAATTTT
AATATATTT
AATATTATT
AATTAATTT
AATTATATT
ATAAATTTT
ATAATATTT
ATAATTATT
ATATAATTT
ATATATATT
Steps: 11
Coefficient: 42
AAAAATTTTTT
AAAATATTTTT
AAAATTATTTT
AAAATTTATTT
AAAATTTTATT
AAATAATTTTT
AAATATATTTT
AAATATTATTT
AAATATTTATT
AAATTAATTTT
...
ATAATAATTTT
ATAATATATTT
ATAATATTATT
ATAATTAATTT
ATAATTATATT
ATATAAATTTT
ATATAATATTT
ATATAATTATT
ATATATAATTT
ATATATATATT
Steps: 13
Coefficient: 132
(etc.)
Steps: 15
Coefficient: 429
(etc.)
Steps: 17
Coefficient: 1430
(etc.)
Steps: 19
Coefficient: 4862
(etc.)
Steps: 21
Coefficient: 16796
(etc.)
Steps: 23
Coefficient: 58786
(etc.)
Steps: 25
Coefficient: 208012
(etc.)
Steps: 27
Coefficient: 742900
(etc.)
Does this random variable have a name? Do you recognise the coefficient?