# How to find the average number of iterations for a variable to reach a number. Suppose I have an infinite loop with a variable x that starts at 0. Every iteration of the loop, x has a 10% chance of being increased by 1 and a 90% chance of being decreased by 1, but it cannot go below 0. How can I calculate the average number of iterations of the loop for x to reach a certain number?

How to find the average number of iterations for a variable to reach a number.
Suppose I have an infinite loop with a variable x that starts at 0. Every iteration of the loop, x has a 10% chance of being increased by 1 and a 90% chance of being decreased by 1, but it cannot go below 0. How can I calculate the average number of iterations of the loop for x to reach a certain number?
You can still ask an expert for help

## Want to know more about Probability?

• Questions are typically answered in as fast as 30 minutes

Solve your problem for the price of one coffee

• Math expert for every subject
• Pay only if we can solve it

broeifl
Step 1
As per MSE protocol, I can't give a full answer, but just to start you off, suppose you want to know the expected # of steps to get to 4 on the natural number line from 0,
we can start by writing $\phantom{\rule{thickmathspace}{0ex}}\phantom{\rule{thickmathspace}{0ex}}{S}_{0}=1+0.1{S}_{1}+0.9{S}_{0}$
Step 2
This equation means that with one step from 0, we either move with $Pr=0.1$ to step 1 or fall back to step 0 (since we can't go below 0) with $Pr=0.9$, and we can frame similar equations step by step, so the four equations will be
${S}_{0}=1+0.1{S}_{1}+0.9{S}_{0}$
${S}_{1}=1+0.1{S}_{2}+0.9{S}_{0}$
${S}_{2}=1+0.1{S}_{3}+0.9{S}_{1}$
${S}_{3}=1+0.9{S}_{2}$