[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
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.
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.
Running/Exploring the Program
Modified: February 18, 2016
Copyright © 2000-2017, Gary Darby All rights reserved.