Say I have 4 flavors of icecream, a, b, c, and d, and I want to get 3 scoops.
So basically I want to generate all possible 4-tuples where the sum of all elements in each tuple adds up to 3, like:
(3, 0, 0, 0) (0, 3, 0, 0) (0, 0, 3, 0) (0, 0, 0, 3) (2, 1, 0, 0) (2, 0, 1, 0) ... and so on, so that to generate all possible 3-scoop outcomes that can exist in menu of 4 flavors.
So for example the 5th 4-tuple I typed above would translate into an item that has 2 scoops of flavor a, 1 scoop of flavor b, no scoops of flavor c and no scoops of flavor d.
Is there a nice way of counting these things and generating them, for all cases where flavors=scoops, flavors>scoops and scoops>flavors...?
Thank you all in advance!