(boxes, balls)
return list(rec(boxes, balls))
Create all nonnegative tuples of length d which sum up to n.
Create all nonnegative tuples of length d which sum up to n.
Create all nonnegative tuples of length d which sum up to n .
def partition(boxes, balls):
    """Create all nonnegative tuples of length d which sum up to n."""
    # <https://stackoverflow.com/a/36748940/353337>
    # See <https://stackoverflow.com/a/45348441/353337> for an alterative
    # solution.
    def rec(boxes, balls, parent=tuple()):
        if boxes > 1:
            for i in range(balls + 1):
                yield from rec(boxes - 1, i, parent + (balls - i,))
        else:
            yield parent + (balls,)

    return list(rec(boxes, balls))
def partition ( boxes , balls ) : # <https://stackoverflow.com/a/36748940/353337> # See <https://stackoverflow.com/a/45348441/353337> for an alterative # solution. def rec ( boxes , balls , parent = tuple ( ) ) : if boxes > 1 : for i in range ( balls + 1 ) : yield from rec ( boxes - 1 , i , parent + ( balls - i , ) ) else : yield parent + ( balls , ) return list ( rec ( boxes , balls ) )