/
ch-2.pl
54 lines (45 loc) · 882 Bytes
/
ch-2.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env perl
=begin comment
---------------------------------------
AUTHOR: Robert DiCicco
DATE : 2023-08-01
Challenge 228 Task 2 Empty Array ( Perl )
---------------------------------------
=cut
use v5.38;
use List::Util qw/min/;
my @myints = ([3, 4, 2],[1,2,3]);
for my $i (@myints) {
say "Input: \@int = (@$i)";
my $cnt = 0;
while(scalar @$i) {
my $min = min(@$i);
if ($i->[0] == $min) {
shift(@$i);
} else {
push(@$i,$i->[0]);
shift(@$i);
}
scalar @$i > 0 ? say "(@$i)" : say "()";
$cnt++;
}
say "Output: $cnt\n";
}
=begin comment
---------------------------------------
SAMPLE OUTPUT
perl .\EmptyArray.pl
Input: @int = (3 4 2)
(4 2 3)
(2 3 4)
(3 4)
(4)
()
Output: 5
Input: @int = (1 2 3)
(2 3)
(3)
()
Output: 3
---------------------------------------
=cut