uwc: ruby implementation
authorRichard Kojedzinszky <krichy@tvnetwork.hu>
Mon, 6 Oct 2014 21:23:12 +0000 (23:23 +0200)
committerRichard Kojedzinszky <krichy@tvnetwork.hu>
Mon, 6 Oct 2014 21:23:12 +0000 (23:23 +0200)
uwc.rb [new file with mode: 0644]

diff --git a/uwc.rb b/uwc.rb
new file mode 100644 (file)
index 0000000..38deebb
--- /dev/null
+++ b/uwc.rb
@@ -0,0 +1,16 @@
+#!/usr/bin/ruby -w
+
+hash = Hash.new(0)
+
+re = /([a-z']+)/i
+
+$stdin.each do |line|
+       line.scan(re).each do |w|
+               w = w[0]
+               hash[w] = hash[w] + 1
+       end
+end
+
+hash.keys.sort_by! { |x| [hash[x], x] }.each do |w|
+       puts "#{w} #{hash[w]}"
+end