Skip to main content

Generates partitions of a positive integer

Project description

partitions

In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing n as a sum of positive integers.

For example, the partitions of 5:

5
4 + 1
3 + 1 + 1
2 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1
2 + 2 + 1
3 + 2

Setup and run

pip3 install partitions

To run on the command-line:

$ partitions 11
11
10 + 1
9 + 1 + 1
8 + 1 + 1 + 1
7 + 1 + 1 + 1 + 1
...

You can also use this in code:

from partitions import partitions
list(partitions(5)) # returns [(5,), (4, 1), (3, 1, 1), (2, 1, 1, 1), (1, 1, 1, 1, 1), (2, 2, 1), (3, 2)]

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

partitions-1.0.0.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

partitions-1.0.0-py3-none-any.whl (3.7 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