Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Letterpress board searcher
#/usr/bin/env ruby
# A brute-force letterpress board searcher. It takes about 90 seconds to search a board.
#
# Good uses: train on your vocabulary with boards you lost on.
#
# LAZY AND STUPID CHEATERS: DO NOT USE THIS FOR CHEATING. CHEATERS NEVER WIN.
class BoardSearcher
attr_reader :board
def initialize(unsorted_board)
@board = unsorted_board.sort
end
def contains(unsorted_candidate)
candidate = unsorted_candidate.sort
candidate_index = 0
@board.each do |letter|
candidate_index += 1 if letter == candidate[candidate_index]
end
(candidate_index == candidate.length) ? true : false
end
end
if __FILE__ == $0
filename = ARGV[0] || "/usr/share/dict/words"
board = (ARGV[1] || "asviqaazotvepjffysjrrasdl").chars.to_a
searcher = BoardSearcher.new(board)
File.foreach(filename) do |line|
candidate = line.downcase.chomp
if searcher.contains(candidate.chars.to_a)
puts candidate
end
end
end
@mariusae

Here's one in ocaml; 10x faster! ~ https://gist.github.com/4013882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.