klocey / partitions

python based code for integer partitioning
4 stars 4 forks source link

last_lexical(14, 4) -> [4, 4, 3, 3] instead of [5, 3, 3, 3] #22

Closed smichr closed 8 years ago

smichr commented 8 years ago

Proposed new routine:

def last_lexical(q, n):
    """ Find the last lexical (i.e. most even) partition of q having n parts
    q : the total sum of the partition
    n : number of parts in the partition
    j : place holder """
    test_qnk(q, n)
    b, _remainder = divmod(q, n)
    partition = [b] * n # largest list of integers whose sum <= n
    # put any remainder on the first element
    partition[0] += _remainder
    return partition
smichr commented 8 years ago

Sorry -- I see that the current behavior is correct.