Skip to main content

Integer partitions with an optional max length

Project description

Restricted Partition

A restricted partition is the subset of an integer partition with only partitions at or below a certain length.

from restricted_partition import iter_partition

iter_partition(5)

# [1, 1, 1, 1, 1]
# [1, 1, 1, 2]
# [1, 1, 3]
# [1, 2, 2]
# [1, 4]
# [2, 3]
# [5]

iter_partition(5, 3)

# [1, 1, 3]
# [1, 2, 2]
# [1, 4]
# [2, 3]
# [5]

Uses the accel_asc algorithm (thank you, Jerome Kelleher), so it is pretty speedy in pure Python.

I found the algorithm at https://jeromekelleher.net/generating-integer-partitions.html.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

restricted_partition-0.1.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

restricted_partition-0.1.1-py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page