Solution of wordchain problem in Ruby.