This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Newsletter Inverse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Newsletter Inverse" Watch "Newsletter Inverse" New topic
Author

Newsletter Inverse

Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

OK, thinking about the June newletter / wordfind problem got me thinking about the inverse. What algortihm can be used to hide words in a grid?
a). Write a program to hide a list of words in a grid. The program should take a list of words and a grid size (through any input means you want), and produce as output a grid with those words hidden in it. Exceptions can be handled any way you see fit (you can't hide "redneck" in a 2x2 grid...). non-used spaces in the grid should be filled with random characters.
b). This is the same as (a), except that instead of a grid size and random-characters, the program uses a string of characters to fill in the empty spaces (usually a quote with spaces removed), thereby producing a "true" word seek puzzle. (Good word seek solvers always look at the left over letters to see what they spell.)

(Ulterior motive: I want to test the newsletter soltutions with different word grids, but I'm too lazy to come up with my own grid... )


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I didn't even see this post before I posted in the other thread! Here's my solution to part a. Part b is not accounted for though I'm afraid.
Start with an empty char[][].
Sort the word list by length, with the longer words first in the list, the idea being that it's easier to insert the longer words in as empty a grid as possible.
For each word {
Obtain a random empty grid space.
Obtain a random direction.
If the word will not fit (that is each letter must either fall across an empty space or a space containing the same letter) in that direction, try all the other directions until a fit is found.
If the word will not fit in any orientation in this grid space, get the next empty grid space and repeat the process.
}
Fill all remaining empty spaces with a random character.
Here's my code, including the GridReference class I used for WordFinder.
WordSearchMaker.java

GridReference.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newsletter Inverse
 
Similar Threads
June Newsletter Puzzle
strings
Boggle game - Algorithms and data structures
Hot to deal with OutOfMemoryError
Hangman BufferReader ??