Created
January 26, 2009 23:52
-
-
Save DRMacIver/53053 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
tag_counts = {} | |
STDIN.lines.each{|l| c, t = l.split; tag_counts[t.strip] = c.to_i } | |
duplicates = Hash.new{|h, k| h[k] = []} | |
tag_counts.keys.each{|k| duplicates[k.gsub(/-|_/, "")] << k } | |
duplicates.values.each{|vs| vs.sort!{|x, y| tag_counts[y] <=> tag_counts[x]} } | |
new_tag_counts = {} | |
duplicates.values.each{|vs| new_tag_counts[vs[0].gsub(/(_|-)+/, "_")] = vs.map{|v| tag_counts[v]}.inject(0, &:+)} | |
puts new_tag_counts.to_a.sort{|x, y| y[1] <=> x[1]}.map{|t, c| " #{c} #{t}" } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment