My wife loves word puzzles. She is amazing at them. Me? Not so much. On the other hand I love programs and programming projects that involved string manipulation. So when my wife started playing a new (to her) word puzzle – the New York Times Spelling Bee – my thoughts went to solving it programmatically.
If you are not familiar with the game, it involves seven letters for the player to make words from. Anny of the letters may be used but only letters from the list can be used. Oh, and there is one letter, shown in the center of the letters, that must be used in every word. Words much be four letters long or longer BTW.
I thought this would be a fun project to code up so I took a pass at it. I think it would be a fun project for use with students as well. It involves a number of interesting and important concepts.
For one thing, you’ll want to open and read through a text file. There are many word lists available on the interne BTW. So that part is easy. You want want to check through a list for any words that are not school appropriate (that suggests other interesting projects now that I think about it).
Looping is obvious of course. As is parsing strings to find if a given letter is or is not included in a word. One method I wrote for my solution was to build a string of letters that were not included in the list of allowed letters. I searched any possible word to make sure that no unallowed letters were part of it.
Have you tried this or a similar project? Would you use this one? If you do, let me know.
Edit: Should of known it had been done before. Useful information at Nifty Assignments.
2 comments:
You can extend the solver by making it be able to give help to the player. I found this a great place to introduce Java Predicates and the removeIf() method from ArrayList. One can invent a "little" language that the helps the user eliminate words. For example !A could mean no letter 'A' in the word. A!3 means word contains an 'A' but not at location 3. Turn this into a Predicate and reduce the list of words accordingly. Starting with the original word list, you can winnow it down using the clues provided after a guess. And at any point you can list the possible words remaining. You can make the little language more complex and create Predicates with ands and ors and nots.
Oops! I was thinking Wordle, not Spelling Bee.
Post a Comment