Rewrite of word_chains.rb. Functional, but could use refactoring.