aboutsummaryrefslogtreecommitdiff
path: root/challenge-337/dave-jacoby/perl/ch-1.pl
blob: 5c79d38024ea9b6843cdc49f76bf0793e1ebc322 (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
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env perl

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

my @examples = (

    [  6, 5, 4, 8 ],
    [  7, 7, 7, 7 ],
    [  5, 4, 3,  2, 1 ],
    [ -1, 0, 3, -2, 1 ],
    [  0, 1, 1,  2, 0 ],

);

for my $in (@examples) {
    my @input  = $in->@*;
    my $input  = join ', ', @input;
    my @output = smaller_than_current(@input);
    my $output = join ', ', @output;
    say <<"END";
        Input:  \@num1 = ($input)
        Output: $output
END

}

sub smaller_than_current (@num1) {
    my @num2;
    for my $i ( 0 .. $#num1 ) {
        my $n    = $num1[$i];
        my @copy = @num1;
        delete $copy[$i];
        @copy = grep { defined } @copy;
        push @num2, scalar grep { $n >= $_ } @copy;
    }
    return @num2;
}