use strict;
use warnings;

use lib 'blib/lib';

use Integer::Partition;
use Getopt::Std;

getopts('lm:n:M:N:', \my %opt);

my $arg;
$arg->{lexicographic} = exists $opt{l} ? 1 : 0;

my $count = 0;
for my $n (@ARGV) {
    print "\n" if $count++;

    my $i = Integer::Partition->new($n, $arg);
    while (my $p = $i->next) {
        next if exists $opt{m} and @$p > $opt{m};
        next if exists $opt{n} and @$p < $opt{n};
        next if exists $opt{M} and grep {$_ > $opt{M}} @$p;
        next if exists $opt{N} and grep {$_ < $opt{N}} @$p;
        print "@$p\n";
    }
}
