Re: Probability Problem

2006-04-25 Thread Tim Peters
[Elliot Temple] > I think I got it. I noticed my code is essentially the same as Tim > Peter's (plus the part of the problem he skipped). I read his code 20 > minutes before recreating mine from Alex's hints. Thanks! > > def main(): > ways = ways_to_roll() > total_ways = float(101**10) >

Re: Probability Problem

2006-04-25 Thread Peter Tillotson
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

Re: Probability Problem

2006-04-25 Thread Elliot Temple
I think I got it. I noticed my code is essentially the same as Tim Peter's (plus the part of the problem he skipped). I read his code 20 minutes before recreating mine from Alex's hints. Thanks! def main(): ways = ways_to_roll() total_ways = float(101**10) running_total = 0

Re: Probability Problem

2006-04-24 Thread Tim Peters
[Alex Martelli] >> ... >> You can compute the requested answer exactly with no random number >> generation whatsoever: compute the probability of each result from >> 0 to 1000, then sum the probabilities of entries that are exactly 390 >> apart. [Elliot Temple] > That was the plan, but how do I ge

Re: Probability Problem

2006-04-24 Thread Alex Martelli
Elliot Temple <[EMAIL PROTECTED]> wrote: > On Apr 24, 2006, at 8:24 PM, Alex Martelli wrote: > > > Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > > > >> In article <[EMAIL PROTECTED]>, > >> Elliot Temple <[EMAIL PROTECTED]> wrote: > >> > >>> Problem: Randomly generate 10 integers from 0-100 in

Re: Probability Problem

2006-04-24 Thread Elliot Temple
On Apr 24, 2006, at 8:24 PM, Alex Martelli wrote: > Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > >> In article <[EMAIL PROTECTED]>, >> Elliot Temple <[EMAIL PROTECTED]> wrote: >> >>> Problem: Randomly generate 10 integers from 0-100 inclusive, and sum >>> them. Do that twice. What is the pro

Re: Probability Problem

2006-04-24 Thread Alex Martelli
Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Elliot Temple <[EMAIL PROTECTED]> 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 think the sum w

Re: Probability Problem

2006-04-24 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>, Elliot Temple <[EMAIL PROTECTED]> 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 think the sum would come close to a normal distribution. -- http://mail.py

Probability Problem

2006-04-24 Thread Elliot Temple
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

Re: Dice probability problem

2006-04-06 Thread Antoon Pardon
On 2006-04-05, Tomi Lindberg <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: > >> def __rmul__(self, num): >> tp = num * [self] >> return reduce(operator.add, tp) >> >> sum3d6 = 3 * D(6) > > One basic question: is there any particular reason not to > use __mul__ instead (that would al

Re: Dice probability problem

2006-04-05 Thread Tomi Lindberg
Antoon Pardon wrote: > def __rmul__(self, num): > tp = num * [self] > return reduce(operator.add, tp) > > sum3d6 = 3 * D(6) One basic question: is there any particular reason not to use __mul__ instead (that would allow me to use both 3 * D(6) and D(6) * 3, while __rmul__ raises an A

Re: Dice probability problem

2006-04-05 Thread Alexander Schmolck
Tomi Lindberg <[EMAIL PROTECTED]> writes: > # Adds another die to results. > def add_dice(sums, die): > # If first die, all values appear once I'd add something like sums = sums or {} because otherwise your function will sometimes mutate sums and sometimes return a fresh object, whi

Re: Dice probability problem

2006-04-05 Thread Tomi Lindberg
Antoon Pardon wrote: > IMO you are making things too complicated and not general > enough. I believe that the above is very likely more than just your opinion :) Programming is just an occasional hobby to me, and I lack both experience and deeper (possibly a good chunk of shallow as well) know

Re: Dice probability problem

2006-04-05 Thread Antoon Pardon
Op 2006-04-04, Tomi Lindberg schreef <[EMAIL PROTECTED]>: > First, thanks to Antoon and Alexander for replying. > > Antoon Pardon wrote: > >> It would be better to construct distributions for one >> die and make a function that can 'add' two distributions >> together. > > As both replies pointed to

Re: Dice probability problem

2006-04-04 Thread Dave Mandelin
That looks reasonable. The operation you are implementing is known as 'convolution' and is equivalent to multiplying polynomials. It would be a little more general if you had the input 'die' be a sequence of the count for each outcome, so d6 would be [1]*6 (or [0]+[1]*6 if you prefer). That would a

Re: Dice probability problem

2006-04-04 Thread Gerard Flanagan
Tomi Lindberg wrote: > > # A die with n faces > D = lambda n: [x+1 for x in range(n)] > That can be written: D = lambda n : range(1,n+1) Gerard -- http://mail.python.org/mailman/listinfo/python-list

Re: Dice probability problem

2006-04-04 Thread Tomi Lindberg
First, thanks to Antoon and Alexander for replying. Antoon Pardon wrote: > It would be better to construct distributions for one > die and make a function that can 'add' two distributions > together. As both replies pointed to this direction, I tried to take that route. Here's the unpolished co

Re: Dice probability problem

2006-04-04 Thread Antoon Pardon
Op 2006-04-04, Tomi Lindberg schreef <[EMAIL PROTECTED]>: > Hi, > > I'm trying to find a way to calculate a distribution of > outcomes with any combination of dice. I have the basics > done, but I'm a bit unsure how to continue. My main concern > is how to make this accept any number of dice, wi

Re: Dice probability problem

2006-04-04 Thread Alexander Schmolck
Alexander Schmolck <[EMAIL PROTECTED]> writes: > addDice(resultFor1, pool[1]) > addDice(pool[0], pool[1]) sorry should have spelled out that successive lines are meant to be equivalent, i.e. addDice(resultFor1, pool[1]) == addDice(pool[0], pool[1]) 'as -- http://mail.python.org

Re: Dice probability problem

2006-04-04 Thread Alexander Schmolck
Tomi Lindberg <[EMAIL PROTECTED]> writes: > I'm trying to find a way to calculate a distribution of outcomes with any > combination of dice. I have the basics done, but I'm a bit unsure how to > continue. My main concern is how to make this accept any number of dice, > without having to write a ne

Dice probability problem

2006-04-04 Thread Tomi Lindberg
Hi, I'm trying to find a way to calculate a distribution of outcomes with any combination of dice. I have the basics done, but I'm a bit unsure how to continue. My main concern is how to make this accept any number of dice, without having to write a new list comprehension for each case? Here'