aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/dave-jacoby/perl/ch-1.pl
blob: 2caa4c1b3c53a5ca50d22ad57915be470844eeaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env perl

use strict;
use warnings;
use experimental qw{ say postderef signatures state };

my @examples = (

    [ -3, 1,  2,  -1, 3, -2, 4 ],
    [ -1, -2, -3, 1 ],
    [ 1,  2 ],

);

for my $example (@examples) {
    my $output = max_pos_neg( $example->@* );
    my @ints   = $example->@*;
    my $ints   = join ',', @ints;
    say <<"END";
    Input:  \@ints = ($ints)
    Output: $output
END
}

sub max_pos_neg (@ints) {
    my $pos = scalar grep { $_ > 0 } @ints;
    my $neg = scalar grep { $_ < 0 } @ints;
    return $pos > $neg ? $pos : $neg;
}