Skip to content

Instantly share code, notes, and snippets.

@girving
Created November 15, 2012 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girving/4079727 to your computer and use it in GitHub Desktop.
Save girving/4079727 to your computer and use it in GitHub Desktop.
Lower and upper bounds for a gambler's ruin problem
#!/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])
@girving
Copy link
Author

girving commented Nov 15, 2012

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