Forums Register Login

Newsletter Inverse

+Pie Number of slices to send: Send
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... )
+Pie Number of slices to send: Send
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
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1598 times.
Similar Threads
June Newsletter Puzzle
Boggle game - Algorithms and data structures
Hangman BufferReader ??
Hot to deal with OutOfMemoryError
strings
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:29:13.