#!/usr/bin/env perl

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

$| = 1;

die "usage: pds_multiply factor [file]...\n"
    if @ARGV < 1 || $ARGV[0] !~ /^(?:0|[1-9][0-9]*)\z/;

my $f = shift @ARGV;

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;
    die "not a planar difference set\n"
        if !Math::DifferenceSet::Planar->verify_elements(@e);

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

    my $s2 = $s->multiply($f);
    my @e2 = $s2->elements;

    print "@e2\n";
}

__END__
=head1 NAME

pds_multiply - multiply a list of planar difference sets by a factor

=head1 SYNOPSIS

  pds_multiply factor [file]...

=head1 DESCRIPTION

This example program reads planar difference sets, one per line, as
integer numbers separated by whitespace, multiplies them by the factor
specified on the command line, and writes the result to standard output.

The factor has to be either a multiplier or a rotator for each difference
set, so that the results are also difference sets, or the program will
fail with an error message.

=head1 AUTHOR

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

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2019 by Martin Becker, Blaubeuren.  All rights reserved.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=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
