As of October, 2016, Embarcadero is offering a free release
of Delphi (Delphi
10.1 Berlin Starter Edition ). There
are a few restrictions, but it is a welcome step toward making
more programmers aware of the joys of Delphi. They do say
"Offer may be withdrawn at any time", so don't delay if you want
to check it out. Please use the
link to let me know if the link stops working.
Support DFF - Shop
If you shop at Amazon anyway, consider
using this link.
We receive a few cents from each
Support DFF - Donate
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.
For over 15 years
Mensa Page-A-Day calendars have provided several puzzles a year
for my programming pleasure. Coding "solvers" is most fun,
but many programs also allow user solving, convenient for "fill
in the blanks" type. Below are Amazon links to the
two most recent years.
365 Puzzlers Calendar 2017
365 Puzzlers Calendar 2018
(Hint: If you can
wait, current year calendars are usually on sale in January.)
e-mail with your comments about this program (or anything else).
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
Suggestions for Further Explorations
would be smart of the program to automatically switch to a higher
level dictionary when solving a user entered puzzle and no solution
is found using the current one. (And switch back to the user
selected dictionary after the search.)
levels could be added by associating a dictionary as well as a range
of word sizes with each level.
test should be made for duplicate words after a puzzle is
generated. I have seen a case where the same random word was
selected twice in the same puzzle.
is a "wrapper" for five previously written programs which
use the dictionary unit. Scrambled Pie should logically be the
|Original Date: April 6, 2004
Modified: July 29, 2017