word search puzzle algorithm