def partition_rec(n, d, depth=0):
    """
    Recursion for generating partitions of integer d of length n

    Parameters
    ----------
    n : int
        Length of partition vector.
    d : int
        Maximum sum of the vector.
    depth : int, optional
        Depth of recursion. The default is 0.

    Returns
    -------
    List
        Partitions in recursive algorithm, used for building partitions list.

    """
    if n == depth:
        return [[]]
    
    P = []
    
    for i in range(d+1):
        for item in partition_rec(n, d-i, depth=depth+1):
            P.append(item + [i])  
              
    return P