Okay, hopefully the third time with #159 is the charm. I decided to
give myself a week before representing the Guardian of Middle-earth
quiz, so instead we have something new. I’ve focused on the core
problem and not attempted to deal with all questions or possibilities
in the description, so this should be better for y’all.
Anyway, onto the quiz!
The three rules of Ruby Q. 2:
Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have passed from the time on this message.
Support Ruby Q. 2 by submitting ideas as often as you can! (A
permanent, new website is in the works for Ruby Q. 2. Until then,
please visit the temporary website at
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby T. follow the discussion. Please reply to
the original quiz message, if you can.
Word Search Generator
A word search puzzle presents a grid of seemingly random letters and a
list of words. The goal of the puzzle is to find and mark all the
words from the list hidden within the grid, searching along straight
lines (horizontal, vertical and diagonal).
Your task for this week’s quiz is to write a Ruby program that
generates word search puzzles, given a list of words and the desired
width and height for the puzzle. A call to the script will look like
genpuzzle.rb words.txt 6x8
The first argument is the list of words, one word per line in a text
file. The second argument is the dimensions of the puzzle, width by
Your program should output two files. The first file, search.txt,
should contain the puzzle itself. All characters should be separated
by spaces to allow the puzzle solver room to mark found words. As an
example, here is a 6x8 puzzle containing the words from “zero” to
“nine”. (Please view with fixed-width font if this does not display
properly in your browser or email program.)
e a e g g w e e n i n t r n o h h f h q e g i r t z i v u q o e e o e l w r f g e s t o u s i x
The second file, solution.txt, should contain the same puzzle with the
answers marked, like this:
e . e . . . | | e e-n-i-n t | | / r n o . h f | \ / / h . e g i r | X / / t z i v u . |/ / X o e e o e . | | / \ w r f . . s | | t o . s-i-x