#
# 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 .
#



###
### partition.pl
###

## Chapter 1 section 8.2

sub partition {
  my $total = 0;
  for my $treasure (@_) {
    $total += $treasure;
  }

  my $share_1 = find_share($total/2, [@_]);
  return unless defined $share_1;
  my %in_share_1;
  for my $treasure (@$share_1) {
    ++$in_share_1{$treasure};
  }

  for my $treasure (@_) {
    if ($in_share_1{$treasure}) {
      --$in_share_1{$treasure};
    } else {
      push @$share_2, $treasure;
    }
  }
  return ($share_1, $share_2);
}
