Skip to content

Instantly share code, notes, and snippets.

@andyjeffries
Created January 7, 2010 16:34
Show Gist options
  • Select an option

  • Save andyjeffries/271348 to your computer and use it in GitHub Desktop.

Select an option

Save andyjeffries/271348 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
require 'rubygems'
require 'Text'
results = {}
Dir.glob("top100_*.txt") do |filename|
File.read(filename).split("\n").each do |song|
stripped = song.gsub(/[^a-z0-9]/, '').downcase
added = false
results.each_key do |key|
if Text::Levenshtein.distance(key, stripped) < 2
results[key][:count] += 1
added = true
end
end
if !added
results[stripped] = {:count => 1, :name => song}
end
end
end
results.sort{|a,b| b[1][:count]<=>a[1][:count]}.slice(0,2).each { |elem|
puts "#{elem[1][:count]}, #{elem[1][:name]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment