Skip to content

Instantly share code, notes, and snippets.

@dastels
Created March 2, 2014 19:11
Show Gist options
  • Select an option

  • Save dastels/9311961 to your computer and use it in GitHub Desktop.

Select an option

Save dastels/9311961 to your computer and use it in GitHub Desktop.
Boggle search
def start
(0...15).each do |start_position|
return true if search(@query,
integer_to_yx(start_position),
[integer_to_yx(start_position)])
end
false
end
...
def search(query, current_pos, bads)
return true if query == "" # it's here!
return false unless @board[current_pos[0]][current_pos[1]] == query[0]
possible_moves = possible_moves(current_pos, bads)
possible_moves.each do |move|
return true if search(query[1..-1], move, bads + move)
end
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment