From: Ken Bloom Date: 2008-09-22T12:02:02+09:00 Subject: Re: One-Liners Mashup (#177 again) In article you wrote: > 2008/9/20 James Coglan : >> def roll(n,s) >> (1..n).map { |x| "#{x}|#{'#' * (1 + rand(s))}" } * "\n" >> end >> >> puts roll(20,4) > > I don't think that your method rolls the dice s times. > > def roll(n, s) > a=(1..n).map{|x|"#{x}|"};s.times{a[rand(n)]< end Here's a ruby 1.9 version that doesn't use semicolons or mutable data structures. def roll n, s ((1..s).to_a+n.times.map{|x| rand(s)+1}).group_by{|x| x}.map{|k,v| "#{k}|"+"#"*(v.size-1)}.join("\n") end --Ken -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/