I know this is a common problem, but this problem has been bugging me after someone asked me it, and I can't find the answer anywhere on the Internet.
Say we have a number line, and we start at the point 0. On each turn, we can move left with the probability of 1/2, or we can move right with the probability of 1/2. What is the expected number of turns until we get x units away on either side? (i.e., I don't care which side I get to, I'll stop when I get x units away)
Let $u(i)$ be the expected number of turns to reach $\pm x$, starting at $i \in \{-x, -x+1, \ldots, x\}$. Then $u(-x) = u(x) = 0$ and if $-x < i < x$, $u(i) = 1 + (u(i-1) + u(i+1))/2$. The general solution of the last equation is $u(i) = a + b i - i^2$, and from the conditions $u(-x) = u(x) = 0$ we get $a = x^2$, $b = 0$. In particular $u(0) = x^2$.