how would you write such programit turns out there' an elegant recursive solution it involves dividing these combinations into two groupsthose that begin with and those that don' suppose we abbreviate the idea of people selected from group of as ( , let' say is the size of the group and is the size of team theorem says that (nk( ( kfor our example of people selected from group of we have ( ( ( we've broken large problem into two smaller ones instead of selecting from group of we're selecting twice from group of firstall the ways to select people from group of then all the ways to select people from group of there are ways to select people from group of in the ( term--which we'll call the left term--these combinations are bcbdbecdcede is the missing group memberso to make three-person teams we precede these combinations with aabcabdabeacdaceade there are four ways to select people from group of in the ( term--the right term--we have bcdbcebdecde when these combinations from the right term are added to the from the left termwe get the combinations for ( you can apply the same decomposition process to each of the groups of for example( is ( added to ( as you can seethis is natural place to apply recursion you can think of this problem as tree with ( , on the top row( , and ( , on the next rowand so onwhere the nodes in the tree correspond to recursive function calls figure shows what this looks like for the ( , example the base cases are combinations that make no sensethose with for either number and those where the team size is greater than the group size the combination ( , is valid but there' no point trying to break it down further in the figuredotted lines show the base casesyou return rather than following them