Click here to Skip to main content
15,891,375 members
Articles / Desktop Programming / MFC
Article

A magic trick

Rate me:
Please Sign up or sign in to vote.
4.38/5 (21 votes)
12 Nov 20032 min read 120.3K   1.5K   27   27
A magic trick that will astound you!

Introduction

While not a tool per se, this little "magic" program was inspired by a Web site that a friend sent me. I thought it neat enough to try and figure out how they did it. Within just a few minutes, a co-worker and I, with the help of a big whiteboard, figured out a solution. The result is a wizard-based dialog program that attempts to read your mind!

How to use

Following the on-screen instructions, it's self explanatory. Basically, you're going to jot down some numbers, scramble 'em up a bit, and the program will attempt to guess one of your numbers. If it guesses wrong, drop me a line and tell me the numbers you used. I may not have accounted for all exceptions.

The program is not fool-proof. It is possible to give it bogus numbers, and it will, in turn, give you a bogus answer. Making it totally fool-proof would have over-complicated the code, which I did once already.

The solution

I chose not to put a solution to the puzzle here, because then it would be way too easy for the casual Web surfer to find it, thus ruining any fun they might have had trying to figure it out the old fashioned way - using their head!

A solution is, however, in the code itself, and is very easy to comprehend (even easier when someone shows you how to simplify your math!). I would challenge you to try the program, or the referenced Web site, a few times before diving right in and looking at the solution.

References

Improvements

The UI is a bit blah, but since my intent was not a flashy program, it matters not. One of these days, I might be so inclined to dress it up a bit. If you like drawing and GDI type stuff, feel free.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Pinnacle Business Systems
United States United States

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

HTTP 404 - File not found
Internet Information Services

Comments and Discussions

 
GeneralCompile error Pin
alrsds8-Sep-09 1:24
alrsds8-Sep-09 1:24 
QuestionRe: Compile error Pin
David Crow8-Sep-09 6:32
David Crow8-Sep-09 6:32 
AnswerRe: Compile error [modified] Pin
alrsds8-Sep-09 14:19
alrsds8-Sep-09 14:19 
QuestionRe: Compile error Pin
David Crow8-Sep-09 16:54
David Crow8-Sep-09 16:54 
AnswerRe: Compile error Pin
alrsds9-Sep-09 5:32
alrsds9-Sep-09 5:32 
Generaldidn't work Pin
donperry27-Jan-07 10:58
donperry27-Jan-07 10:58 
GeneralRe: didn't work Pin
David Crow29-Jan-07 2:46
David Crow29-Jan-07 2:46 
GeneralModified Code Pin
Douglas R. Keesler31-Dec-04 15:39
Douglas R. Keesler31-Dec-04 15:39 
Generalremember the ABACUS!! Pin
Douglas R. Keesler31-Dec-04 8:29
Douglas R. Keesler31-Dec-04 8:29 
GeneralYour works cause good discussions. Pin
LAT14-Nov-03 20:17
LAT14-Nov-03 20:17 
GeneralA Better Trick Pin
DanYELL14-Nov-03 13:39
DanYELL14-Nov-03 13:39 
GeneralRe: A Better Trick Pin
UltraJoe18-Nov-03 1:41
UltraJoe18-Nov-03 1:41 
GeneralMore magic Pin
Mr Scotty14-Nov-03 1:04
Mr Scotty14-Nov-03 1:04 
GeneralRe: More magic Pin
David Crow14-Nov-03 8:45
David Crow14-Nov-03 8:45 
GeneralThis is NOT magic. Pin
WREY13-Nov-03 19:33
WREY13-Nov-03 19:33 
GeneralRe: This is NOT magic. Pin
pistarino13-Nov-03 21:45
pistarino13-Nov-03 21:45 
GeneralRe: This is NOT magic. Pin
WREY14-Nov-03 6:27
WREY14-Nov-03 6:27 
GeneralRe: This is NOT magic. Pin
David Crow14-Nov-03 8:52
David Crow14-Nov-03 8:52 
GeneralRe: This is NOT magic. Pin
WREY14-Nov-03 15:04
WREY14-Nov-03 15:04 
NO! NO! NO! The illusion used to show that 1 + 1 = 3 DOES NOT USE "The divide by zero" trick you mentioned. ABSOLUTELY NOT!!!

With regards to your sample, (like the '1 + 1 = 3' suggestion you made that it must be using the 'divide by zero' trick), you are WRONG. I am NOT using a brute force approach. It has some AI in it (sort of) that determines the most promising route to take in finding an answer.

Specifically, I am suggesting taking a "Graph-traversal tree" approach (in which you set up a tree graph structure) then do a "depth-first" search on the graph, followed by a "breath-first" search on a particular node that seems to hold promises of a good lead. (Sort of similar to deciphering the numbers of a combination lock, where whenever you obtain one of the correct numbers, you resume the search from one qualifying node to the next qualifying node that I referred to as the "breath-first" search.)

Think of the problem as a friend challenging you to find the house where he/she lives, by giving you only the number of the house (less one digit), and although you were NOT given the street name, presume other particulars as the name of the city, etc., were also given, plus one more important clue: the correct number does not have a 'zero' in it.

If the friend gave you two numbers, you will immediately know that their house number is comprised of three digits (and four digits if he/she gave you three numbers). The brute force way would be to go down every street and look at every house number that has every digits given to you included in them, plus one unknown digit (which by trial and error you will include in the number for which you're searching). Eventually (like a very long time later), you are bound to find the house. That's using the brute force method!!

If you're a math person, you'll immediately know that to use brute force will inversely vary your chance of finding the correct house, with the size of the city, and you'll immediately abandon that approach as hopeless. IOW, brute force is OUT!!

The graph approach says, "find all the streets that are long enough to have these many houses, using these possible combination of numbers." That would immediately eliminate a bunch of streets (such as those with less than a hundred houses on them). To then relapse to using brute force, would be that you'd start checking every house (on streets with more than 100 houses) to see which ones have digits (minus one) that were given to you. Again, plain common sense should tell you that using such an approach is less than optimal; try a smarter way.

To further eliminate bad leads, a more optimal approach would be for you to set up a kind of graph with positions on the street (represented by nodes) where by extrapolating the numbers, you'd have a good idea where the possibilty of a certain house ought to be with a candidate number. For example, if you're working with just these two numbers, '2' and '9', the third missing number will be any from 1 through 9. Therefore, you set up the graph to show where the possibility might be, that a house (beginning with the lowest possible number) would most likely be situated. This means you'll begin with 129, followed by 192, then 219 followed by 291 (etc.). That's the permutation to which I referred earlier. This means you'll figure out, most likely where on a particular street would house #129 would be, followed by where house #192 would be (etc.). This means you're discretely checking only certain houses and skipping a lot others. This is NOT a door to door search you're using!!! and no brute force is being applied in your method; just maths, common sense and the Law of Probability.

Big Grin | :-D

William

Fortes in fide et opere!
GeneralOverly complex math Pin
John Plsek10-Oct-03 4:06
John Plsek10-Oct-03 4:06 
GeneralFido puzzle discussion Pin
Steve Mayfield9-Oct-03 20:38
Steve Mayfield9-Oct-03 20:38 
GeneralRe: Fido puzzle discussion Pin
David Crow10-Oct-03 2:26
David Crow10-Oct-03 2:26 
GeneralRe: Fido puzzle discussion Pin
John Plsek10-Oct-03 4:38
John Plsek10-Oct-03 4:38 
GeneralThis is a nice application. Pin
73Zeppelin9-Oct-03 16:00
73Zeppelin9-Oct-03 16:00 
GeneralRe: This is a nice application. Pin
John Plsek10-Oct-03 4:44
John Plsek10-Oct-03 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.