Homework 2: Word Search Maker

Please try this in a language that you would like to learn, or are not very familiar with, so that you push your limits a little. Bring a solution with you next time and we’ll chat about our approaches, the languages and techniques we used, and what we thought.

Bring your solutions to our September meeting.

The problem is from an old Ruby Quiz. I will provide a link later (the problem page also has the solution on it). For now, I will give you the problem here directly.

Write a program that takes in a text file containing a list of words, one per line, and also the width and height for a grid of letters. Your program should output a word-search grid of the requested size that contains all of the words in the word list. Each word should be in a straight line, and can be in any of 8 directions.

The words.txt file is an arbitrary list of words. Make up your own list of words to use. Here is a small example:

dog
cat
spot

The output can contain any letters in any positions so long as each word in the given words.txt word list appears at least once in the grid in some direction (up, down, left, right, or the 4 diagonals).

Most of the time there will be many right answers. The goal is to simply pack the words into the grid. This may become difficult if many words are provided and the grid is fairly small.

Sample run:

./searchmaker words.txt 4 4

Sample output:

pcot
dgoa
tpac
sgod

If you look close enough, you can find “dog”, “cat”, and “spot” in the output, which is the only requirement.

Feel free to discuss the problem or any other topics you are interested in on our mailing list (accessible via our Meetup Group).

Provided Solutions

Bill R.

Bob C.

Gary D.

Frank W.