25 lines
1.6 KiB
Plaintext
25 lines
1.6 KiB
Plaintext
The set of combinations with repetitions is computed from a set, <math>S</math> (of cardinality <math>n</math>), and a size of resulting selection, <math>k</math>, by reporting the sets of cardinality <math>k</math> where each member of those sets is chosen from <math>S</math>.
|
|
In the real world, it is about choosing sets where there is a “large” supply of each type of element and where the order of choice does not matter.
|
|
For example:
|
|
:Q: How many ways can a person choose two doughnuts from a store selling three types of doughnut: iced, jam, and plain? (i.e., <math>S</math> is <math>\{\mathrm{iced}, \mathrm{jam}, \mathrm{plain}\}</math>, <math>|S| = 3</math>, and <math>k = 2</math>.)
|
|
|
|
:A: 6: {iced, iced}; {iced, jam}; {iced, plain}; {jam, jam}; {jam, plain}; {plain, plain}.
|
|
|
|
<small>Note that both the order of items within a pair, and the order of the pairs given in the answer is not significant; the pairs represent multisets.</small>
|
|
<br><small>Also note that ''doughnut'' can also be spelled ''donut''.</small>
|
|
|
|
|
|
;Task:
|
|
* Write a function/program/routine/.. to generate all the combinations with repetitions of <math>n</math> types of things taken <math>k</math> at a time and use it to ''show'' an answer to the doughnut example above.
|
|
* For extra credit, use the function to compute and show ''just the number of ways'' of choosing three doughnuts from a choice of ten types of doughnut. Do not show the individual choices for this part.
|
|
|
|
|
|
;References:
|
|
* [[wp:Combination|k-combination with repetitions]]
|
|
|
|
|
|
;See also:
|
|
{{Template:Combinations and permutations}}
|
|
<br><br>
|
|
|