#
# This software is Copyright 2005 by Elsevier Inc.  You may use it
# under the terms of the license at http://perl.plover.com/hop/LICENSE.txt .
#



###
### make_partition
###

## Chapter 5 section 2

sub make_partition {
  my $n = shift;
  my @agenda = [$n];
  return Iterator {
    while (@agenda) {
      my $item = pop @agenda;
      my ($largest, @rest) = @$item;
      my $min = $rest[0] || 1;
      my $max  = int($largest/2);
      for ($min .. $max) {
        push @agenda, [$largest-$_, $_, @rest];
      }
      return $item;
    }
    return;
  };
}
