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


Problem DescriptionA championship 18 hole golf course has holes with a par scores of 3, 4,
or 5 strokes and a total par for the course of 72 strokes.

In general for selecting R things from N there are N x (N1) x (N2) ... (NR+1) permutations. This is often written using factorial notation. N factorial, written N!, is the product of consecutive integers from 1 to N. The number of permutations can be expressed as N! / (NR)! In our example, 2 of 18 can be written 18! / 16! or 18 x 17. 
The number of possible arrangements of holes for each a, b, c set is a little more complicated. Assume that we need to select all possible arrangements of sets of two par 3 holes. My first thought was that we have 18 choices for the first selection and 17 choices for the second, or 18 X 17 = 306 ways total. This is the number of permutations of 2 things selected from 18 .
But ... notice that the 306 permutations includes the pairs (hole1, hole2) and (hole2, hole1) for any two holes. These shouldn't count twice since the order in which we selected the par 3 holes doesn't matter to the player (he'll play from 1 through 18 regardless of how we assigned the par values to the holes). The phrase "order doesn't matter" is our clue that we actually need the number of combinations, the unique ways we can select 2 things from 18. The number of combinations is the number of permutations with the duplicates removed. How many duplicates are there? For each pair (x, y) selected in our 306 choices there is a corresponding pair (y, x), so we need to divide the number of permutations by 2. If we were selecting 3 holes, there would be 6 duplicates of each triplet selected (x, y ,z), (x, z, y), (y, x, z), (y, z, x), (z, x, y), (z, y, x) so we would have to divide the permutation count by 6. In general when selecting R things there will be R! duplicates. Since the number of permutations is N! / (NR)!, the number of combinations is sometimes formulated as (N!) / ((NR)! x R!).
In the Permutes and Combinations functions in this program that we won't use the factorial formulas  instead we'll just multiply or divide by the index of a loop as necessary to compute the result.
So far we've only discussed selecting the number of unique arrangements for one of the hole sizes. Say we need a par 3's, the number is given by Combinations(a,18). To complete the calculation we need to select say b par 4's from the remaining 18a holes. This is given by Combinations(b,18a). The c par 5's can only be selected in one way, since c is 18ab by definition and there are only 18ab holes remaining. The total ways we can select the par 3's and 4's is the product of the two combination values. Answers should be the same of course, no matter which two hole sizes are used for these calculations.
You could add
code to check for yourself that it doesn't matter which pair of hole sizes
are used in the calculation, or in which order. In other words if
the number of holes of par 3, 4, and 5 is given by a, b, c; it
should be the case that:
Combinations(a,18)*Combinations(b,18a) = Combinations(b,18)*Combinations(a,18b) = Combinations(a,18)*Combinations(c,18a) = Combinations(c,18)*Combinations(a,18c) = Combinations(b,18)*Combinations(c,18b) = Combinations(c,18)*combinations(b,18c)


The Permutes and Combinations routines both need some error checking to ensure that the first parameter does not exceed the second. 
Modified: February 18, 2016
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 20002017, Gary Darby All rights reserved. 