A fun challenge: Word puzzle in ObjC and Xojo

A recent Tweet: https://twitter.com/iljawascoding/status/1391742982806773763

I cheated and wrote an app to solve my daughter’s English homework. It finds all words in a character matrix, no matter their orientation.

I challenged myself to write this in Xojo, and seeing how fast I can make it.

The first incarnation was actually a bit faster than the ObjC version. After that, the original author optimized his code (main factor is that he could rely on a case-sensitive dictionary, whereas I could not with the classic Xojo API - I wonder if the new API can do this better?)

So I tried to improve the algorithm. I caught up a bit, but then lost to the fact that better algorithms need more data preparation time. So, while my latest version would find the words faster than his simpler version, mine would also need a LOT more time to prepare before starting the search.

If you are interested in how this works, or even add your own improvements, you can find the code here (if you alter my version and like me to share it on github, please keep the old methods intact):



Nice app :slight_smile:

Although it does not run correctly in Xojo. Clicking a word will often offset the character selection by 2 rows/columns and ends up with an OutOfBoundsException for some hits.

Oops. Let me fix that quickly. It should work right with the “simple” Method, but I made a mistake in the latest tree algos.

The fix is in ByteNode.FindIn: The line

result.Append line.Left (pos)

needs to be:

result.Append line.Mid (startPos, pos-startPos+1)

I’ve updated my github repo accordingly.

1 Like