I seem to have a Boggle solver that I wrote some time ago. This follows from Cheken's plan. It gets called a little differently (you supply a word list file and a text file with a 4x4 grid as arguments), but I decided it was worth it. Also note that it refers to βQβ as βQUβ, so there is additional logic for this.
require 'set' def build_dict(dict, key, value) if key.length == 0 dict[:a] = value else if key[0] == "q" first = key[0..1] rest = key[2, key.length - 1] else first = key[0] rest = key[1, key.length - 1] end dict[first] = {} unless dict.has_key? first build_dict(dict[first], rest, value) end end dict = {}
user24359
source share