Skip to content

Instantly share code, notes, and snippets.

@lune-sta
Created January 19, 2015 17:53
Show Gist options
  • Save lune-sta/6f9c62c7c33d21988113 to your computer and use it in GitHub Desktop.
Save lune-sta/6f9c62c7c33d21988113 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*
Encoding.default_external = 'UTF-8'
require 'pp'
dir = "./"
hash = Hash.new{|k, v| k[v] = Hash.new}
nums = []
Dir::glob(dir + "*.txt").each do |f|
nums << n = f.scan(/\d+/)[0].to_i
open(f).read.split("\n").each do |a|
count, word = a.split
hash[word][n] = count.to_i
end
end
hash.each do |word, h|
nums.each do |n|
h[n] = 0 unless h[n]
end
end
puts hash.map {|word, h|[h.sort{|(k1,v1),(k2,v2)|v2<=>v1}[0][1], word]}.sort{|a,b|b<=>a}[0..100].map{|a|a.join(" = >")}.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment