Probability Problem
- From: Elliot Temple <curi@xxxxxxx>
- Date: Mon, 24 Apr 2006 19:19:22 -0700
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/
.
- Follow-Ups:
- Re: Probability Problem
- From: Peter Tillotson
- Re: Probability Problem
- From: Lawrence D'Oliveiro
- Re: Probability Problem
- Prev by Date: Re: Coming from delphi - looking for an IDE - willing to spend money
- Next by Date: Re: Hooking things up in GUI application
- Previous by thread: Coming from delphi - looking for an IDE - willing to spend money
- Next by thread: Re: Probability Problem
- Index(es):
Relevant Pages
|