Gambler Ruin Momentum

xprev = a
x = a
while true:
    z = -1 {p} 1
    tmp = x
    x = 2*x - xprev + z
    xprev = tmp
end