Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Lower and upper bounds for a gambler's ruin problem

View gambler.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/env python
 
from __future__ import division
from numpy import *
 
def iter(n,boundary):
p = ones(n)
b = boundary.copy()
j = 3*arange(1,n)
for i in xrange(1000):
b[:n] = p
p[1:] = .5*(p[:-1]+b[j])
return p
 
print repr(iter(1000,zeros(3000))[1])
print repr(iter(1000,((1-sqrt(5))/2)**arange(3000))[1])
Owner

Output:

cone:~% ./gambler 
0.57477536382958938
0.57477536382958938
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.