Do you finish the Word Search in the Sunday paper? Several years ago, Robert Matthews decided to design a word search to help his kids in their school work.
Matthews wanted to be able to put in the words of his choice and provide difficulty levels so that game users could progress to harder and harder levels. He needed a program that would place the words automatically and ensure that the words didn’t overlap too much.
Matthews presented his design at the SouthEast Users Groups (SESUG) conference in Durham, NC. According to Matthews, designing a program that would do what he wanted turned out to be a little more complicated than he thought.
First, determine the size of your matrix. “Totally up to you how big or small your matrix is,” he said.
The next steps are to:
- Determine the starting row and column.
- Pick a direction; do you want all of the words to be horizontal and vertical or do you want the program to pick a random direction?
- Specify the ending row and column.
- Ensure that the ending row and column are within the matrix.
- Check to see if an existing word in the matrix is being overwritten. You don’t want to overlap the words by more than one letter.
When the code picks a word and location on the matrix, it goes in a random order. The program knows where the words are and picks one at a time. “When it gets close to the end of the matrix, it [the program]really has to look for a place to put the words,” Matthews said.
After the matrix is complete, the program fills in the remaining space with random letters. As soon as the computer has input all of the words, Matthews says to print the matrix; this provides the player or a checker with an answer key. “You don’t want to look for the words you just completed,” he said.
“This was an interesting little programming challenge.”
In a couple of days, you can find Matthew’s paper on the SESUG site. This paper is a bit fun, but I’m sure you can find other uses for the code. Take a look at all of the papers and let me know which one you’ll use right away.
Image provided by jbcurio // attribution by creative commons