Probability Problem

Peter Tillotson none at no.chance
Tue Apr 25 06:35:43 EDT 2006


I had a possibly similar problem calculating probs related to premium
bond permutation. With 10^12 memory ran out v quickly. In the end I got
round it by writing a recursive function and quantising the probability
density function.

Elliot Temple wrote:
> Problem: Randomly generate 10 integers from 0-100 inclusive, and sum
> them. Do that twice. What is the probability the two sums are 390 apart?
> 
> I have code to do part of it (below), and I know how to write code to do
> the rest. The part I have calculates the number of ways the dice can
> come out to a given number. The problem is the main loop has 9
> iterations and it takes about 2.5 minutes to begin the 4th one, and each
> iteration is about 101 times longer than the previous one. So:
> 
>>>> x = 2.5 * 101**6
>>>> x /= (60*24*365.25)
>>>> x
> 5045631.5622908585
> 
> It'd take 5,000 millennia. (If my computer didn't run out of memory
> after about 4 minutes, that is.)
> 
> Any suggestions? Either a way to do the same thing much more efficiently
> (enough that I can run it) or a different way to solve the problem.
> 
> Code:
> 
> li = range(101)
> li2 = []
> range101 = range(101)
> for x in xrange(9):
>     print "x is %s" % x
>     li2 = []
>     for y in li:
>         for z in range101:
>             li2 += [y+z]
>     li = li2
> print li.count(800)
> # prints how many ways the dice can add to 800
> 
> 
> This link may help:
> http://www.math.csusb.edu/faculty/stanton/m262/intro_prob_models/calcprob.html
> 
> 
> -- Elliot Temple
> http://www.curi.us/blog/
> 



More information about the Python-list mailing list