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
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
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
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
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
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
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
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
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
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
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
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'
12 matches
Mail list logo