Algorithm to find words in a puzzle