From 3169b4b509cabaaf83fb0d8a2788b644f7d3e286 Mon Sep 17 00:00:00 2001 From: Ray Toal Date: Wed, 28 Jan 2015 09:29:05 -0800 Subject: [PATCH] A first try at a Ruby golf --- 06-code-golf/tf-06.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 06-code-golf/tf-06.rb diff --git a/06-code-golf/tf-06.rb b/06-code-golf/tf-06.rb new file mode 100755 index 0000000..e61852e --- /dev/null +++ b/06-code-golf/tf-06.rb @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +require 'set' + +stops = ((IO.read '../stop_words.txt').split ',').to_set +ARGF.read.downcase.scan(/[a-z]{2,}/).each_with_object(Hash.new 0){|w,c|c[w]+=1 if not stops.member? w}.sort_by{|w,c|-c}[0,25].each{|w,c|puts "#{w} - #{c}"} +