QQuotaMosaic
Workflows

Coding workflows · Largest-remainder allocation

03
Built around your work

A concrete starting point

Allocate up to 10000 integer seats across at most 1000 nonnegative integer weights using largest remainders. Check zero weights and tied remainders with input-order tie-breaking, rejecting a positive allocation with zero total weight before division.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Largest-remainder allocation

A concrete starting point
def allocate(weights, seats):
    if type(weights) not in (list, tuple) or len(weights) > 1000:
        raise ValueError("weights.container")
    weights = tuple(weights)
    if type(seats) is not int or not 0 <= seats <= 10000:
        raise ValueError("seats.range")
    if len(weights) > 1000 or any(type(w) is not int or w < 0 for w in weights):
        raise ValueError("weights.invalid")
    total = sum(weights)
    if total == 0:
        if seats:
            raise ValueError("weight.zero")
        return [0] * len(weights)
    result = [w * seats // total for w in weights]
    remaining = seats - sum(result)
    order = sorted(range(len(weights)), key=lambda i: (-(weights[i] * seats % total), i))
    for i in order[:remaining]:
        result[i] += 1
    return result

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗