/
ch-1.pl
38 lines (31 loc) · 822 Bytes
/
ch-1.pl
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
#!usr/bin/env perl
use strict;
use warnings;
use feature 'say';
=begin comment
--------------------------------------
AUTHOR: Robert DiCicco
DATE : 2023-05-29
Challenge 219 Sorted Squares Task 1 ( Perl )
--------------------------------------
=cut
my @list = ([-2, -1, 0, 3, 4],
[5, -4, -1, 3, 6]
);
my $cnt = (scalar @list) ;
while ($cnt--) {
say "Input: \@list = [@{$list[$cnt]}]";
my @squared_array = map { $_ ** 2 } @{$list[$cnt]};
my @sorted = sort { $a <=> $b } @squared_array;
print "Output: ",join(", ", @sorted), "\n\n";
}
=begin comment
--------------------------------------
SAMPLE OUTPUT
perl .\SortedSquares.pl
Input: @list = [5 -4 -1 3 6]
Output: 1, 9, 16, 25, 36
Input: @list = [-2 -1 0 3 4]
Output: 0, 1, 4, 9, 16
--------------------------------------
=cut