ssoroka (owner)

Revisions

gist: 24825 Download_button fork
public
Public Clone URL: git://gist.github.com/24825.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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. :)