David Landgren
and 1 contributors

# NAME

Integer::Partition - Generate all integer partitions of an integer

# VERSION

This document describes version 0.05 of Integer::Partition, released 2013-06-23.

# SYNOPSIS

``````  use Integer::Partition;

my \$i = Integer::Partition->new(4);
while (my \$p = \$i->next) {
print join( ' ', @\$p ), \$/;
}
# produces
4
3 1
2 2
2 1 1
1 1 1 1

my \$j = Integer::Partition->new(5, {lexicographic => 1});
while (my \$p = \$j->next) {
print join( ' ', @\$p ), \$/;
}
# produces
1 1 1 1 1
2 1 1 1
2 2 1
3 1 1
3 2
4 1
5``````

# DESCRIPTION

`Integer::Partition` takes an integer number and produces an object that can be used to generate all possible integer partitions of the original number in either forward or reverse lexicographic order.

# METHODS

new

Creates a new `Integer::Partition` object. Takes an integer as a parameter. By default, the partitions appear in reverse order, as the algorithm is slightly faster. Forward ordering uses a different, slightly slower algorithm (which is nonetheless much faster than any existing algorithm).

next

Returns the partition, or `undef` when all partitions have been generated.

reset

Resets the object, which causes it to enumerate the arrangements from the beginning.

``  \$p->reset; # begin again``

# DIAGNOSTICS

## missing or undefined input

The `new()` method was called without an input parameter, which should be a positive integer.

## `n` is not a positive integer

The `new()` method was called with zero or a negative integer.

## `n` is not an integer

The `new()` method was called with a number containing a decimal component. Use `int` or `sprintf '%d'` on the input if necessary.

# NOTES

This module implements the Zoghbi and Stojmenovic ZS1 and ZS2 algorithms for generating integer partitions. See http://www.site.uottawa.ca/~ivan/F49-int-part.pdf for more information. These algorithms have been proven to have constant average delay, that is, the amount of effort it takes to produce the next result in the series.

They are the fastest known algorithms known for generating integer partitions (with the ZS1 reverse lexicographic order algorithm being slightly faster than the ZS2 lexicographic order algorithm).

# BUGS

None known.

Please report all bugs at http://rt.cpan.org/NoAuth/Bugs.html?Dist=Integer-Partition|rt.cpan.org

Make sure you include the output from the following two commands:

``````  perl -MInteger::Partition -le 'print \$Integer::Partition::VERSION'
perl -V``````

Pull requests on Github may be issued at https://github.com/dland/Integer-Partition.

# ACKNOWLEDGEMENTS

Thanks to Antoine Zoghbi and Ivan Stojmenovic, for sharing their discovery with the world on the internet, and not hiding it in behind some sort of pay-wall.