Search

 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.

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

Contact

 Search DelphiForFun.org only

Problem Description

The five Olympic rings overlap to create 9 separate areas. Assign the digits 1 through 9 to the areas so that the numbers in each circle sum to the same value.

Background & Techniques

The Olympics are underway, so it must be time to dig out this Olympic rings problem.    The problem is one of the type that can be solved by the BruteForce program which generates all permutations.   I decided to see if I could implement a version in a more straightforward manner.

The problem in equation form states that A+B = B+C+D = D+E+F = F+G+H = H+I with the condition that all variables are in the range from 1 to 9 and no two variables have the same value.    By grouping into separate equations and eliminating common variables, we get the four equations: A=C+D, B+C = E+F, D+E = G+H, and F+G = I.

The program has a print option for those that may want to try solving it by hand before looking at the program's solutions.

Programmer's Notes

There are a few procedures worth mentioning:

DrawRings creates the ring images.  By eyeball, I set the top row centers at 1/3 and the bottom row centers 2/3 down from the top.   Horizontal centers are placed at intervals of 1/6 of the width.    The coolest part of the procedure is a feature not 1 person in 100 would probably notice.  The rings are correctly interlaced!  See image above and note that successive intersections go over and under adjacent rings.  The is done using the arc procedure to  redraw small portions of the rings as necessary to put them back on top.

SolveBtnClick searches for solutions by nesting 9 loops, one for each variable and each running from 1 to 9.  This solution is not very elegant, but it is straightforward. The only tiresome part  is testing and using the continue verb to skip processing for any value that has already been assigned to another variable.    When we get to the last level with 9 different values, it's just a matter of checking to see if these  values satisfy the four equations listed above.

The PrintBtnClick procedure cheats and uses the simple form print method to display the ring image.  I clean up the form somewhat before printing:  hiding buttons, setting backgrounds to white,  and removing the letters from unsolved images (in case the user wants to fill in his own answers).

Finally, I left in the Button1Click procedure that was used to save the rings image as a bmp file.  That image was used to produce the gif image you see above.

Further Explorations

 A version that allowed online user play would be nice, i.e. let the user type numbers into each area and keep track of the sum in each ring for him/her. While documenting this puzzle, I was careful to state that one digit goes into each of the nine areas.   What if we removed that restriction?

Modified:  May 15, 2018