The three rules of Ruby Q.:
-
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. by submitting ideas as often as you can:
- Enjoy!
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.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
by Daniel F.
Today’s quiz would’ve been most useful in elementary school, where over
half of
the homework assignments were word search puzzles. The concept of these
puzzles
is simple enough that an elementary school student could understand it:
given a
box of letters, find a line containing the letters of a specified word
in order.
For example, find the words ruby, dan, rocks, and matz in the following
text:
U E W R T R B H C D
C X G Z U W R Y E R
R O C K S B A U C U
S F K F M T Y S G E
Y S O O U N M Z I M
T C G P R T I D A N
H Z G H Q G W T U V
H Q M N D X Z B S T
N T C L A T N B C E
Y B U R P Z U X M S
The correct answer in the correct output format:
+ + + R + + + + + +
+ + + + U + + + + +
R O C K S B + + + +
+ + + + + + Y + + +
+ + + + + + + + + M
+ + + + + + + D A N
+ + + + + + + T + +
+ + + + + + Z + + +
+ + + + + + + + + +
+ + + + + + + + + +
Notice that the words can go backwards and diagonally, and can intersect
one
another. Searching is case insensitive.
The word search solver should accept input entered by the user after
running the
program, i.e., not exclusively through STDIN or a file, by entering the
puzzle
line by line, pressing return after each line. A blank line indicates
the end of
the puzzle and the start of the comma separated words to find. The
following
example shows how a user would enter the above puzzle, with descriptive
text
from the program removed.
$ ./wordsearch.rb
UEWRTRBHCD
CXGZUWRYER
ROCKSBAUCU
SFKFMTYSGE
YSOOUNMZIM
TCGPRTIDAN
HZGHQGWTUV
HQMNDXZBST
NTCLATNBCE
YBURPZUXMS
Ruby, rocks, DAN, matZ
Now, by itself, this quiz is fairly simple, so I offer an additional
challenge.
Write a beautiful, extensible, and easily-modifiable program without
looking at
the extra credit before starting. When you’re done, try implementing
extra
credit options using less than 5 or 6 (reasonable) lines of code.
* An output format superior to the one given. The output format given
should remain the default unless both formats don't differ on a
textual basis. That should sound cryptic until pondered, I can't
give too much away!
* Allow for "snaking" of answers, in other words, the letters
composing a word don't have to be in a straight line.
* An option to give a hint, i.e., "The word ruby traverses the bottom
left and bottom right quadrants."
* Decide what to do with accented letters.
* Allow for wildcard letters.