#!/usr/bin/env perl

use 5.022;
use strict;
use warnings;
use Math::DifferenceSet::Planar;

$| = 1;

while (<<>>) {
    s/^\s+//;
    my @e = split /\s+/;
    next if !@e;

    die "integer numbers separated by whitespace expected\n"
        if grep { !/^(?:0|[1-9][0-9]*)\z/ } @e;

    my $s = Math::DifferenceSet::Planar->from_elements(@e);

    my $s2 = $s->gap_canonize;;
    my @e2 = $s2->elements_sorted;

    print "@e2\n";
}

__END__
=head1 NAME

pds_gap_canonize - translate planar difference sets to smallest values

=head1 SYNOPSIS

  pds_gap_canonize [file]...

=head1 DESCRIPTION

This example program reads planar difference sets, one per line, as
integer numbers separated by whitespace, translates them so that each
plane is represented by the set with smallest maximum value, and writes
the result to standard output, with elements sorted numerically in
ascending order.

This can be used as an alternative to L<pds_canonize> to pick plane
representatives.

=head1 AUTHOR

Martin Becker, E<lt>becker-cpan-mp I<at> cozap.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2022 by Martin Becker, Blaubeuren.

This library is free software; you can distribute it and/or modify it
under the terms of the Artistic License 2.0 (see the LICENSE file).

=head1 DISCLAIMER OF WARRANTY

This library is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.

=cut
