In article <a245658d0809201035q6a76601ao140ffe56ff219334 / mail.gmail.com> you wrote:
> 2008/9/20 James Coglan <jcoglan / googlemail.com>:
>> 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)]<<?#};puts a
> 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/