文字の 4x4 グリッドに基づいて単語ジェネレーターを作成しようとしています (以下)。

ルールは次のとおりです。
- 文字を繰り返すことはできません
 - 単語は隣接する文字で形成する必要があります
 - 単語は、水平、垂直、または斜め左、右、または上下に形成できます
 
現在、私は 16 文字の入力を受け取り、辞書内のすべての単語をループして、その単語がグリッド上の文字でつづられるかどうかを判断しています。
#!/usr/bin/ruby
require './scores'   # alphabet and associated Scrabble scoring value (ie the wordValue() method)
require './words.rb' # dictionary of English words (ie the WORDS array)
# grab users letters
puts "Provide us the 16 letters of your grid (no spaces please)"
word = gets.chomp.downcase
arr = word.split('')
# store words that can be spelled with user's letters
success = []
# iterate through dictionary of words
WORDS.each do |w|
    # create temp arrays
    dict_arr = w.split('')
    user_arr = arr.dup
    test = true
    # test whether users letters spell current word in dict
    while test
        dict_arr.each do |letter|
            if (user_arr.include?(letter))
                i = user_arr.index(letter)
                user_arr.delete_at(i)
            else
                test = false
                break
            end
        end
        # store word in array
        if test 
            success << w
            test = false
        end
    end
end
# create hash for successful words and their corresponding values
SUCCESS = {}
success.each do |w|
  score = wordValue(w)
  SUCCESS[w] = score
end
# sort hash from lowest to smallest value
SUCCESS = SUCCESS.sort_by {|word, value| value}
# print results to screen
SUCCESS.each {|k,v| puts "#{k}:  #{v}"}
ただし、このアプローチでは、ボード上のタイルの位置が考慮されていません。 4x4 グリッド内の位置に基づいて作成できる単語を見つけるにはどうすればよいでしょうか?
上の画像のボード ゲームの場合、Ubuntu を実行している VM が 1185 の可能な単語を計算するのに約 1.21 秒かかります。/usr/share/dict/words にある Ubunut で提供されている単語の辞書を使用しています