From 3a4cbc746cb3fe57a98dc2c6ad519483f3f9044e Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 16 Sep 2020 00:56:07 +0100 Subject: Add nunovieira220 perl solution to challenge 078 --- challenge-078/nunovieira220/perl/ch-1.pl | 18 ++++++++++++++++++ challenge-078/nunovieira220/perl/ch-2.pl | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 challenge-078/nunovieira220/perl/ch-1.pl create mode 100644 challenge-078/nunovieira220/perl/ch-2.pl 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 -- cgit