• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Newsletter Inverse

Posts: 1840
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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... )
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic