diff options
| -rwxr-xr-x | challenge-115/stuart-little/perl/ch-1.pl | 26 | ||||
| -rwxr-xr-x | challenge-115/stuart-little/perl/ch-2.pl | 8 |
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..")); |
