[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
Selecting from the numbers 1 through 9, place one digit in each of the
circles representing points on Cupid's bow according to the following rule:
For every solution you find" said Cupid before flying off, "you win
someone's heart. If you can find a solution in which the numbers connected by the
bow string qualify as well, you will
always be in love!"
Background & Techniques
This is mainly another little programming exercise using our old standby Combo unit to generate all permutations of 5 of 9 digits. We will test each set to see if it satisfies the conditions. An Edges array of points defines the circles that are connected. For referencing in Edges, circles are numbered like this.
The 6 parts of the bow and arrow (excluding the bow string) are defined in the first 6 points of the array. The 7th and 8th entries identify the circles connected by the bowstring.
As we get each permutation, we'll check if the first 6 edges define numbers that are divisible by 7 or 13 taking the numbers in either order. Function IsOK performs the test for a particular edge, returning true if that edge meets the condition for the current permutation. The current permutation is is contained in an array Combos.Selected through Combos.Selected after each call to Combos.GetNext.
If it is a solution, we'll perform an IsOK check for the bowstring points and just add a note if they also satisfy the condition,
The only other tricky parts might be the use of the FormPaint method to draw the bow. This is necessary since we are drawing the bow directly on the form's canvas. And we use an OnClick exit for the listbox to draw the solution numbers on the bow.
Running/Exploring the Program
Suggestions for Further Explorations
Copyright © 2000-2018, Gary Darby All rights reserved.