No, the mis-understanding is all mine. You are right, otherwise it
will include an extra roll. It should be:
(1..self).to_a.inject(0){|x,y| x + rand(sides)}+self
Further proof of the value of good unit tests. (Since (1..1).to_a
returns a single-member array, you need to provide inject with an
initial value to make it work.)
Regards,
Paul.
On 1/9/06, Gregory Seidman <gsslist+ruby / anthropohedron.net> wrote:
> } # roll the dice
> } (0..self).to_a.inject{|x,y| x + rand(sides)}+self
>
> I think I may be misunderstanding something here. You use 0..self, when I
> would think it would have to be either 0...self or 1..self to get the right
> number of rolls. Am I off? In my solution I used 1..self in much the same
> way.