aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-31 21:32:27 +0100
committerGitHub <noreply@github.com>2021-05-31 21:32:27 +0100
commit9d6b90d66f8a2efda4bd7745e1305abe83b1ab4f (patch)
treebe67e36668d31f9cf2ae98e5640d63414ec302b9
parente2459686f1a5d772babb516ea3ead63485da5645 (diff)
parent810283e640387e46df704ca52817e5d2da64ed78 (diff)
downloadperlweeklychallenge-club-9d6b90d66f8a2efda4bd7745e1305abe83b1ab4f.tar.gz
perlweeklychallenge-club-9d6b90d66f8a2efda4bd7745e1305abe83b1ab4f.tar.bz2
perlweeklychallenge-club-9d6b90d66f8a2efda4bd7745e1305abe83b1ab4f.zip
Merge pull request #4175 from stuart-little/stuart-little_115_perl
1st commit on 115_perl
-rwxr-xr-xchallenge-115/stuart-little/perl/ch-1.pl26
-rwxr-xr-xchallenge-115/stuart-little/perl/ch-2.pl8
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-115/stuart-little/perl/ch-1.pl b/challenge-115/stuart-little/perl/ch-1.pl
new file mode 100755
index 0000000000..37f07065b2
--- /dev/null
+++ b/challenge-115/stuart-little/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <space-separated strings>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use List::AllUtils qw(any);
+
+sub others($ix,$arr) {
+ my @others = $arr->@[ grep {$_ != $ix} keys @{$arr}];
+ return \@others;
+}
+
+sub canChain($words,$start,$end) {
+ (! scalar @{$words}) && return 0;
+ scalar @{$words} == 1 && do {
+ return 0+(substr($words->[0],0,1) eq $start && substr($words->[0],-1) eq $end);
+ };
+ my @startIdxs = grep { substr($words->[$_],0,1) eq $start } keys @{$words};
+ return 0+(any { canChain(others($_,$words),substr($words->[$_],-1),$end) } @startIdxs);
+}
+
+say((scalar @ARGV < 2) ? (0) : (0+(canChain(others(0,\@ARGV),substr($ARGV[0],-1),substr($ARGV[0],0,1)))));
diff --git a/challenge-115/stuart-little/perl/ch-2.pl b/challenge-115/stuart-little/perl/ch-2.pl
new file mode 100755
index 0000000000..e360d703a8
--- /dev/null
+++ b/challenge-115/stuart-little/perl/ch-2.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <space-separated digits>
+
+my $attemptedOut = (join "", sort {$b cmp $a} @ARGV) =~ s/(.)([13579]*)$/$2$1/r;
+say(($attemptedOut =~ m/[02468]$/) ? ($attemptedOut) : ("No even digits.."));