Here's a simple "Mind Reading" program
which can be quite amazing.
of a two digit number, subtract the sum of the digits from the number and
look up the symbol which corresponds to the result. Visualize the
symbol and click the "Show me" button. The program will
Background & Techniques
I ran across this mind reader puzzle in the "Favorite
Links" section of a recent issue of WinXPnews
newsletter (Vol 5,5 Issue 161). I have not identified the original author,
but search Google for "Mindreader sum digits"
and you'll find a number of online versions.
Non-programmers are welcome to read on, but may
want to skip to the bottom of the page to
download executable version of the program.
There are about 60 lines of user written code here,
which puts it in the Beginners category. The only
semi-tricky part is the use of an OnDrawCell exit for displaying
the result numbers and their associated symbol. Each cell requires
two DrawText calls with different fonts; "Arial" for the
numbers and "Wingdings" for the symbols. The table is
filled from a set of symbols selected to avoid those that might standout
by being darker than the others.
A TImage control is used to display the
result and there is a bit of code required to center the symbol within the
image. The left coordinate is 1/2 the difference between
the width of the image and the width of the symbol. Makes sense if
you think about it and the technique can be used in many
"centering" applications. The width of the available
space minus width used gives you the total unused space. To center
the line or image we need half this unused space on the left leaving the
other half on the right. Vertical centering uses the same idea
with the two heights.
Oh - one more tricky part - the advanced
technology required to perform the mind reading task. But I'll let
you discover that for yourselves.
Running/Exploring the Program