Equation Search

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW

Search DelphiForFun.org

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 feedback 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 purchase.  Thanks


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.

Mensa Daily Puzzlers

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.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only




Problem Description

Given four sets of numbers with four numbers in each set, write an equation that is satisfied by each set of numbers.  The numbers are labeled A,B,C,D.  Operations may include +, -, , and .   Any letter may appear in any location in the equation.  Equations will have the form (letter operation letter) operation letter = letter, for example (A+B)D=C,  or  (D-C) A=B.   Parentheses surround the first two letters so operations can always be performed from left to right.     

Background & Techniques

Notes for  non-programmers:  

This program is loosely based on a problem type included in the Mensa Number Puzzles, Harold Gale, Carton Books.   It generates random problems within difficulty constraints set by the user.  

The Options button can be used to modify the included init file, EquSearch.ini,  to control several variables:  

bulletControlling equation complexity -   
bulletOperators: specify which of the four operators, +, -,  , , are to be used in creating equations.
bulletMaximum values:- specify the largest number used in creating problems
bulletProblem set size:  problems are presented in sets with a reward screen shown for sufficiently high scores in any set.    
bulletMinimum score for reward - expressed as a decimal, default value is 0.75  

The "reward" screen  as distributed shows a default image and plays a "Cheers.wav" audio file when displayed.   If additional .wav files are included in the same folder as the program, one is selected randomly to accompany the reward screen.   If any .jpg image files are included in the program file, one is randomly selected to display in the reward screen.  

Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.


Notes for programmers:

There are a number of Delphi features used here that may be new to beginning or intermediate programmers, Here are some examples:

bulletI used the init file, TIniFile, component to hold the run time options defined above.  

Note on ReadBool usage:  It's not very well defined, but boolean values in an init file must be specified as 0 for false or 1 for true (actually any non-zero value for true).

bulletSpecial characters for multiply and divide: I referred to the FontViewer program to refresh my memory about the location of the special characters  and and used them throughout this program since non-programmers may not recognize * and   as multiply and divide. 
bulletFindFirst & FindNext functions are used to identify Jpg and Wav files for use in the reward dialog.
bulletComponent arrays: the six lists used to construct equations are put into an array for ease of use.  
bulletThe Controls array within each of the four panels containing the sets of numbers is scanned to find the numbers in the Tedits  when evaluating equations.    Rather than use names or tag values to identify how the edits correspond to the A ,B. C, D labels, I simply made sure that the edits were encountered in A, B, C, D order.    To do this, remember that controls are arranged in the order that they are drawn, called Z-order. Since those drawn first me ay be overlaid by those drawn later, the effect is drawing from back to front.   So right clicking a control and selecting "Send To Back" moves the control to the top of the list .   Doing this for D, C ,B, and A in that order ensures that  they will be retrieved in the expected order (A, B, C, D). 

That brief outline that may be enough to get you started, so let's go!.   

  Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Make the parentheses locations variable.
There are multiple solutions for most (all?) sets of numbers.  How many? Does the number depend on the operators used?


Original:  May 25, 2002

Modified:  May 15, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.