From: Paul Novak Date: 2006-01-09T23:04:18+09:00 Subject: Re: [QUIZ.SOLUTION] Dice Roller (#61) We don't need no steenking leexer/parsers 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 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.