2008/6/6 Peñá, Botp <botp / delmonte-phil.com>: > From: Robert Klemme [mailto:shortcutter / googlemail.com] > # Here's a variant: > <snip> > > i was not going to send my soln since many had already sent theirs (and ias busy playing :)), Isn't it fun to play with something like this? :-) > yet i was surprise how similar was mine to robertk's, so... (just happy that i can be as good as robertk ..sometimes ;) Uh, oh, *cough* Thank you! > C:\family\ruby>cat test.rb > > # a = age > # n = name > hist = Hash.new { |h,a| h[a] = [] } > DATA.each do |entry| > n, a = entry.split /\s*?,\s*/ > break if a.nil? > hist[a.to_i] << n.strip.capitalize It took me some time to realize that #to_i is actually the bit that strips comments. Very clever! > end > > hist.sort_by{|a| a}.each do |a,n| > s = n.size > puts "#{a} -> #{s} #{"x"*s} (#{n.sort.join(', ')})" > end > > __END__ > Bob, 2 > Jim ,2 > eric, 4 # note: > RoB, 5 # i can put comments > bot, 4 #this is me :) > justin, 4, unneeded extras > joe,zero > > --- no more here ---- > > C:\family\ruby>ruby test.rb > 0 -> 1 x (Joe) > 2 -> 2 xx (Bob, Jim) > 4 -> 3 xxx (Bot, Eric, Justin) > 5 -> 1 x (Rob) > > C:\family\ruby> Nice! Kind regards robert -- use.inject do |as, often| as.you_can - without end