diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2020-09-16 00:56:07 +0100 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2020-09-16 00:56:07 +0100 |
| commit | 3a4cbc746cb3fe57a98dc2c6ad519483f3f9044e (patch) | |
| tree | b2f138fe48d21982231fbd3d8124ba8c9cb95d8a | |
| parent | e6e0d55c682c04f3522971870e82dd7a19add027 (diff) | |
| download | perlweeklychallenge-club-3a4cbc746cb3fe57a98dc2c6ad519483f3f9044e.tar.gz perlweeklychallenge-club-3a4cbc746cb3fe57a98dc2c6ad519483f3f9044e.tar.bz2 perlweeklychallenge-club-3a4cbc746cb3fe57a98dc2c6ad519483f3f9044e.zip | |
Add nunovieira220 perl solution to challenge 078
| -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 |
