This blog accompanies the video tutorial on building a Boggle solver that works in reverse… and does it surprisingly well (for smaller board sizes; it won’t be as effective for a 100x100 board). Instead of finding words on the board, it checks if each word can be formed from the board.
What You’ll Learn
- How to reverse the typical Boggle solving approach.
- How to search for a word on a 2D board using recursion.
- How brute force can be “good enough” with the right constraints.
Project Code
You’ll find the complete source code here: simple-boggle-solver
How It Works
The Idea
Most Boggle solvers start with the board and try to construct words by exploring every path. We’re doing the opposite: for each word in the dictionary, we check if it can be found on the board.
Step 1: Read the Board
We represent the board as a Dict[Position, str]
. We pass it to our solver as a single string of length board_size * board_size
return
Step 2: Load the Dictionary
We use /usr/share/dict/words
and filter out anything too short or capitalized or hyphenated
=
Step 3: Try Every Word
We scan each word in the dictionary and check if it can be formed on the board, using a recursive backtracking function that searches from every matching first letter.
...
return
Step 4: Report Matches
Print all valid words found and sort by length or score.
External Resources
Stay in the Loop
Have questions or ideas for more coding adventures? Drop a comment on the video, or suggest the next project idea you want to reinvent!
Thanks for following along, and until next time. Keep reinventing!