Created
January 19, 2015 17:53
-
-
Save lune-sta/6f9c62c7c33d21988113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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