Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Letterpress board searcher

View board_searcher.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#/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

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.