Addendum in case anyone is looking for a software solution:
I stumbled upon this problem, and needed a Pythonic solution to list all of the allowed arrangements. This is the solution I got by reformatting code from Ben Paul Thurston:
def stars_and_bars(num_objects_remaining, num_bins_remaining, filled_bins=()):
"""
The Stars and Bars (https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)) problem can be thought of as
1. Putting m-1 bars ("|") in amongst a row of n stars
OR
2. Putting n balls into m bins.
This program lists all the possible combinations by doing so.
"""
if num_bins_remaining > 1:
# case 1: more than one bins left
novel_arrangement = [] # receptacle to contain newly generated arrangements.
for num_distributed_to_the_next_bin in range(0, num_objects_remaining + 1):
# try putting in anything between 0 to num_objects_remaining of objects into the next bin.
novel_arrangement.extend(
stars_and_bars(
num_objects_remaining - num_distributed_to_the_next_bin,
num_bins_remaining - 1,
filled_bins=filled_bins + (num_distributed_to_the_next_bin,),
)
# one or multiple tuple enclosed in a list
)
return novel_arrangement
else:
# case 2: reached last bin. Termintae recursion.
# return a single tuple enclosed in a list.
return [
filled_bins + (num_objects_remaining,),
]
So for example, if you'd like to list all the ways to write $N=6$-tuple of nonnegative integers such that they sum up to $M=10$, you can call the function
print(stars_and_bars(10, 6))