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
|
#!/usr/bin/env perl
use strict;
use warnings;
use experimental qw{ say postderef signatures state };
my @examples = (
[ 5, 2, 1, 6 ],
[ 1, 2, 0, 3 ],
[ 0, 1 ],
[ 9, 4, 9, 2 ],
);
for my $example (@examples) {
my @output = smaller_than( $example->@* );
my $input = join ', ', $example->@*;
my $output = join ', ', @output;
say <<~"END";
Input: \@ints = ($input)
Output: ($output)
END
}
sub smaller_than (@ints) {
return map {
my $i = $_;
scalar grep { $_ < $i } @ints;
} @ints;
}
|