Skip to content

Instantly share code, notes, and snippets.

@ssoroka
Created November 14, 2008 08:36
Show Gist options
  • Save ssoroka/24825 to your computer and use it in GitHub Desktop.
Save ssoroka/24825 to your computer and use it in GitHub Desktop.
# find two words that share the same pluralization for tpope. :D
# Steven Soroka
# http://blog.stevensoroka.ca
require 'ansi' # sudo gem install ssoroka-ansi
# load words with an array of words.
# words = IO.read("/usr/share/dict/words").split("\n").uniq # or something,
# then take out a crap load or it'll take till christmas 2053
#1=0, 2=1, 3=3, 4=6, 5=10, 6=15, etc
def f(n)
n -= 1
sum = n
while n > 1 do
n -= 1
sum += n
end
sum
end
puts "it will take #{f(words.size)} operations to process #{words.size} words..."
matches = []
max = words.size
words.each_with_index{|w,i|
printf ANSI.left(60) + "#{i} / #{max}; matches: #{matches.size}"
(i+1..words.size-1).each{|j|
if w.pluralize == words[j].pluralize
matches << [w, words[j], w.pluralize]
end
}
}
# granted, this is super slow. :) it'd be faster to make a table of pluralizations and then compare them,
# and maybe only check within the same starting letter(s). meh. :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment