Skip to content

Instantly share code, notes, and snippets.

@lune-sta
Created January 4, 2015 14:44
Show Gist options
  • Save lune-sta/4f3a9ecf9365bb46124d to your computer and use it in GitHub Desktop.
Save lune-sta/4f3a9ecf9365bb46124d to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*
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
hash.map{|a|[a[0]] + a[1].sort.map{|b|b[1]}.flatten}.transpose.each do |a|
puts a.join("\t")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment