Largest Remainder (Hamilton method) algorithm for rounding values while preserving the total.
Project description
largest-remainder 
Utilities for working with the Largest Remainder (Hamilton) apportionment
algorithm. The package exposes a single LargestRemainder helper that rounds
floating point allocations to integers while preserving the requested total.
Features
- ✅ Deterministic rounding that always matches the requested total
- ✅ Supports both sequences and mappings while keeping the original order of keys
- ✅ Fully type annotated API with comprehensive unit tests
Installation
The package is published on PyPI. Install it with your preferred Python package manager:
pip install largest-remainder
# or
uv add largest-remainder
Usage
from largest_remainder import LargestRemainder
# Round a list of quotas to an integer total
LargestRemainder.round([1, 2, 3], total=10)
# -> [2, 3, 5]
# Round a mapping and keep the original keys
LargestRemainder.round({"a": 1.0, "b": 2.0}, total=10)
# -> {"a": 3, "b": 7}
Values can be any non-negative numbers. The algorithm scales the inputs so that
their sum matches the requested total and then distributes the remaining units
to the elements with the largest fractional parts.
Development
- Install the development dependencies using uv:
uv sync --all-extras --dev
- Run the linters and unit tests:
uv run ruff check . uv run mypy uv run pytest
Contributing and community
Contributions are welcome! Please read CONTRIBUTING.md for instructions on setting up a development environment and submitting changes. Participation in this project is governed by the Code of Conduct.
Security
If you discover a security issue, please follow the process described in SECURITY.md.
License
This project is licensed under the terms of the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file largest_remainder-0.1.0.tar.gz.
File metadata
- Download URL: largest_remainder-0.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aafe96c856e04705432c0174b55b3d05df03cc49b2d80f1293b72954d710cf0c
|
|
| MD5 |
40ad728f0a36eb7be05da225184aee97
|
|
| BLAKE2b-256 |
ebb3bc99fdc6a0648e5705f752c10a929e41d726f31cc5e59cbe4f5408358e26
|
Provenance
The following attestation bundles were made for largest_remainder-0.1.0.tar.gz:
Publisher:
release.yml on fido-id/largest-remainder-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
largest_remainder-0.1.0.tar.gz -
Subject digest:
aafe96c856e04705432c0174b55b3d05df03cc49b2d80f1293b72954d710cf0c - Sigstore transparency entry: 627550622
- Sigstore integration time:
-
Permalink:
fido-id/largest-remainder-py@20dfad9f2daa18a867b36020f101495df50ce740 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fido-id
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@20dfad9f2daa18a867b36020f101495df50ce740 -
Trigger Event:
push
-
Statement type:
File details
Details for the file largest_remainder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: largest_remainder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f1918ca72fa7e2c66790f348f49c5bb06511512c247566d2735a2a57fd7e8fd
|
|
| MD5 |
b1d39ffeae50b0d0edc1b7b9b904a4c6
|
|
| BLAKE2b-256 |
3aea8d145e08efcebd680560c7d9ee87bb90513549b2f81531a784dd70105770
|
Provenance
The following attestation bundles were made for largest_remainder-0.1.0-py3-none-any.whl:
Publisher:
release.yml on fido-id/largest-remainder-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
largest_remainder-0.1.0-py3-none-any.whl -
Subject digest:
0f1918ca72fa7e2c66790f348f49c5bb06511512c247566d2735a2a57fd7e8fd - Sigstore transparency entry: 627550684
- Sigstore integration time:
-
Permalink:
fido-id/largest-remainder-py@20dfad9f2daa18a867b36020f101495df50ce740 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fido-id
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@20dfad9f2daa18a867b36020f101495df50ce740 -
Trigger Event:
push
-
Statement type: