Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / bench / shootout / wordfreq.ruby
blob9135366d23aff084b1112df79b22ebc2c0a7ff6d
1 #!/usr/bin/ruby
2 # -*- mode: ruby -*-
3 # $Id: wordfreq.ruby,v 1.2 2004-07-03 05:36:11 bfulgham Exp $
4 # http://shootout.alioth.debian.org/
6 freq = Hash.new(0)
7 loop {
8 data = (STDIN.read(4095) or break) << (STDIN.gets || "")
9 for word in data.downcase.tr_s('^A-Za-z',' ').split(' ')
10 freq[word] += 1
11 end
13 freq.delete("")
15 lines = Array.new
16 freq.each{|w,c| lines << sprintf("%7d %s\n", c, w) }
17 print lines.sort.reverse