Given a set of 4 partial words, each missing then
same single letter, identify the missing letter and unscramble the words.
Background & Techniques
This puzzle is a type that occurs occasionally in the Mensa®
Daily Puzzle Calendar. It is logical combination of of two
programs already included in Wordstuff2:
Unscramble which unscrambles word anagrams, and Crossword Helper,
which fills in missing letters in partial words.
Solving the puzzles is essentially an offline exercise, not much need
to tell the computer the words once you have found them. But
it will generate new puzzles for you at several levels of
difficulty. Levels 1 through 4 choose from words increasing
length. By loading larger dictionaries, puzzles generated at
each level become much harder to solve. The default dictionary
(Small.dic) contains less than 2000 words for the program to choose
from. General.dic contains about 17,000 words and Full.dic
has about 62,000 words! The pie image above is a typical level
1 puzzle generated with Full.dic. Not an easy puzzle
although there are at least two choices for the missing letter.
The program will also solve puzzles that it generates (wow!) or that
you enter manually (if, for example, you can't solve a Mensa calendar
version and for some reason don't want to turn the page to find the
.Non-programmers are welcome to read on, but
may want to skip to the bottom of this page to
download executable version and the dictionaries for this program.
We had four main problems to solve in writing the program:
Program Logic - finding the solution when
then user clicks the "find it for me" button
I modeled Scrambled Pie
after Unscramble with two changes in the logic - we don't have to
worry about generating two and three word phrases from the scrambled
letter, which simplifies things a lot. But because the missing
letter is unknown, we append all possible letters to each of the
partial words and then look for a letter that produced anagrams of
valid words in all four cases.
the pie figure.
A TImage provides the canvas for the
pie. The interesting part was placing the letters randomly with
each quadrant without overlapping each other or the borders of the
quadrant. I used polar coordinates to randomly select and angle
in the appropriate quadrant for the current word (a) and a
distance (r) from the center. For each (r,a) pair,
convert back to Cartesian (x,y), determine the pixel size of
the current letter and see if this rectangle overlaps either another
quadrant or another letter that has already been placed in this
quadrant. If so, try again until a good position is
Printing the puzzle text
Printing is always harder than it seems it
should be. Because printer resolution is several times higher
than monitor resolution, drawing the canvas to the printer produces a
very small image, and stretching the display canvas to the printer
canvas size produces a lousy (low resolution) image. The
only solution is to rerun the code that drew the original image
to the monitor using the printer canvas instead. This
means that the drawing routines must have "Canvas" as
a parameter. One other note - the font "PixelsPerInch"
property must be set to printer resolution if necessary.
The pie part of the image is drawn to a temporary bitmap which is then
copied to the printer canvas. The temp bitmap canvas
needed to know that the resolution was high so that the TextOut
procedure could use more pixels while drawing the
Printing the solution
words up-side down at the bottom of the page.
Inverted text problem was interesting enough
that I wrote a separate test program and posted it over in
All-in-all, there's plenty enough non-trivial code here to put this
program in the advanced category. And there are only a
couple of these puzzles in each year's Mensa calendar (and the answer to
those can be obtained by flipping the page over). So I guess we've
proved once again that the journey is more important that the
Running/Exploring the Program