diff options
| -rw-r--r-- | challenge-078/nunovieira220/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-078/nunovieira220/perl/ch-2.pl | 27 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-078/nunovieira220/perl/ch-1.pl b/challenge-078/nunovieira220/perl/ch-1.pl new file mode 100644 index 0000000000..3cd1fa33f2 --- /dev/null +++ b/challenge-078/nunovieira220/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# Input +my @list = scalar @ARGV ? @ARGV : (9, 10, 7, 5, 6, 1); + +# Get leader elements +my @arr = (); +for my $item (@list) { + @arr = grep { $_ > $item } @arr; + push @arr, $item; +} + +# Output +my $res = join ", ", @arr; +print $res."\n";
\ No newline at end of file diff --git a/challenge-078/nunovieira220/perl/ch-2.pl b/challenge-078/nunovieira220/perl/ch-2.pl new file mode 100644 index 0000000000..80d345396b --- /dev/null +++ b/challenge-078/nunovieira220/perl/ch-2.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# Input +my @A = (7, 4, 2, 6, 3); +my @B = (1, 3, 4); + +# Execute left rotation +my @arr = (); +my $index = 0; + +for my $i (@B) { + my $jump = $i - $index; + + for(my $j = 0; $j < $jump; $j++) { + my $val = shift @A; + push @A, $val; + } + + $index += $jump; + + # Output + my $res = join ", ", @A; + print $res."\n"; +}
\ No newline at end of file |
