aboutsummaryrefslogtreecommitdiff
path: root/challenge-078
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-14 10:18:26 +0100
committerGitHub <noreply@github.com>2020-09-14 10:18:26 +0100
commitebe87ea277270767a6deb260e1bd68c316a94f18 (patch)
tree84470a50514973a9307bc2cae84eeb23faff1613 /challenge-078
parent3077ec98b156d8ca59216bc950354d3ca43716c2 (diff)
parent93ee64552c1f01ab842b6877e549d44fe824bd89 (diff)
downloadperlweeklychallenge-club-ebe87ea277270767a6deb260e1bd68c316a94f18.tar.gz
perlweeklychallenge-club-ebe87ea277270767a6deb260e1bd68c316a94f18.tar.bz2
perlweeklychallenge-club-ebe87ea277270767a6deb260e1bd68c316a94f18.zip
Merge pull request #2286 from davorg/master
Solutions to challenge #78
Diffstat (limited to 'challenge-078')
-rw-r--r--challenge-078/dave-cross/perl/ch-1.pl20
-rw-r--r--challenge-078/dave-cross/perl/ch-2.pl17
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-078/dave-cross/perl/ch-1.pl b/challenge-078/dave-cross/perl/ch-1.pl
new file mode 100644
index 0000000000..c61d1b6455
--- /dev/null
+++ b/challenge-078/dave-cross/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+use List::Util 'all';
+
+my @leaders = map { $ARGV[$_] }
+ grep { is_leader($_, @ARGV) } 0 .. $#ARGV;
+
+say '(', join(', ', @leaders), ')';
+
+sub is_leader {
+ my ($needle, @haystack) = @_;
+
+ return 1 if $needle == $#haystack;
+
+ return all { $haystack[$needle] > $_ } @haystack[$needle + 1 .. $#haystack];
+}
diff --git a/challenge-078/dave-cross/perl/ch-2.pl b/challenge-078/dave-cross/perl/ch-2.pl
new file mode 100644
index 0000000000..47c45d8708
--- /dev/null
+++ b/challenge-078/dave-cross/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my ($array, $idx) = @ARGV;
+my @array = split /,/, $array;
+my @idx = split /,/, $idx;
+
+say '[', join(', ', rotate($_, @array)), ']' for @idx;
+
+sub rotate {
+ my ($idx, @array) = @_;
+
+ return @array[$idx .. $#array], @array[0 .. $idx - 1];
+}