三分之二的直方图Ruby

时间:2014-11-23 09:10:31

标签: ruby histogram

我想把标签放在线程上

a = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
tab1 = Hash[*a.group_by{ |v| v }.flat_map{ |k, v| [k, v.size] }]
puts t1=Thread.new{tab1}
puts t2=Thread.new{tab1}
t1.join
t2.join

1 个答案:

答案 0 :(得分:0)

你的问题不清楚。此?

a = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
tab1 = proc { Hash[a.group_by{ |v| v }.map{ |k, v| [k, v.size] }] }
t1 = Thread.new(&tab1)
t2 = Thread.new(&tab1)
p t1.value
p t2.value