``````
unit U_GolfCourses;
{,,,,,,,,,,,,, Code snipped ...............}

{************** Permutes **********}
function permutes(r,n:integer):int64;
{compute nbr of permutations of n things taken r at a time
as n*(n-1)*(n-2)....*(n-r-1)}
var  i:integer;
begin
if r=0 then result:=1
else
begin
result:=n;
for i:= 1 to r-1 do result:=result*(n-i);
end;
end;

{*************** Combinations ***********}
function combinations(r,n:integer):int64;
{computer nbr of combinations of n things taken r at a time
as permutes(r,n) divided by r! (i.e. r*(r-1)*(r-2)...*2)}
var i:integer;
begin
result:=permutes(r,n);
for i := 2 to r do result:=result div i;
end;

{**************** SolveBtnClick **************}
procedure TForm1.SolveBtnClick(Sender: TObject);
var
a,b,c:integer;
p: real;
pword:string; {"arrangement" (singular) or "arrangements" (plural)}
begin
listbox1.clear;
nbrholes:=holesedt.value;
totpar:=paredt.value;
{try all possible combinations of hole sizes checking for those that
meet the conditions}
for a:= 0 to nbrholes do
for b:= 0 to nbrholes-a do
begin
c:=nbrholes-a-b;
If (3*a+4*b+5*c=totpar) then
begin
p:=combinations(a,nbrholes)*combinations(b,nbrholes-a);
if p=1 then pword:='arrangement' else pword:='arrangements';
listbox1.items.add(format('%3d par three, %3d par four, %3d par five,'
+' (with %1.0n %s)'  ,[a,b,c,p, pword]));
end;
end;
end;

end.

``````