How many Golf Courses?

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

 

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.

Contact

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

Search DelphiForFun.org only

 

 

Problem Description

A 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.

So how many different combinations of holes could there be that meet these conditions? (For extra credit, how many arrangements of each of the possible combinations?)


Background & Techniques

Here's a little program that should provide some  practice working with permutations and combinations.    We need to select triples of hole counts (a, b, c) of par 3, 4 and 5 holes that satisfy the equations: a + b + c =18 and 3a + 4b + 5c = 72.  We'll accomplish this  by trying all possible combinations in a nested loop letting a run from 0 to 18 while b runs from 0 to 18-a.   For each a and b, set c = 18-a-b and see if the total of the par scores for all 18 holes is 72.   If so, we have a solution.  

 In general for selecting R things from N there are N x (N-1) x (N-2)  ... (N-R+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! / (N-R)!   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! / (N-R)!,  the number of combinations is sometimes formulated as (N!) / ((N-R)! 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 18-a holes.  This is given by Combinations(b,18-a).  The c  par 5's can only be selected in one way, since c  is 18-a-b by definition and there are only 18-a-b 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. 

Running/Exploring the Program 

Suggestions for Further Explorations

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,18-a) = Combinations(b,18)*Combinations(a,18-b) = Combinations(a,18)*Combinations(c,18-a) = Combinations(c,18)*Combinations(a,18-c) = Combinations(b,18)*Combinations(c,18-b) = Combinations(c,18)*combinations(b,18-c) 

 

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 2000-2016, Gary Darby    All rights reserved.