aboutsummaryrefslogtreecommitdiff
path: root/challenge-115
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2021-06-13 10:54:01 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2021-06-13 10:54:01 -0400
commit96aeafd6603b8a36258b6212e84552e6670aa89a (patch)
treef74af5bc0494c9fc6e86ec3dd6514fa1ad52cffe /challenge-115
parent4830b1d50fd610eb2424fe284cb48a2795e0478c (diff)
downloadperlweeklychallenge-club-96aeafd6603b8a36258b6212e84552e6670aa89a.tar.gz
perlweeklychallenge-club-96aeafd6603b8a36258b6212e84552e6670aa89a.tar.bz2
perlweeklychallenge-club-96aeafd6603b8a36258b6212e84552e6670aa89a.zip
Challenge 115 by Jaldhar H. Vyas.
Diffstat (limited to 'challenge-115')
-rw-r--r--challenge-115/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-115/jaldhar-h-vyas/perl/ch-1.pl19
-rwxr-xr-xchallenge-115/jaldhar-h-vyas/perl/ch-2.pl22
-rwxr-xr-xchallenge-115/jaldhar-h-vyas/raku/ch-1.raku19
-rwxr-xr-xchallenge-115/jaldhar-h-vyas/raku/ch-2.raku22
5 files changed, 83 insertions, 0 deletions
diff --git a/challenge-115/jaldhar-h-vyas/blog.txt b/challenge-115/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..3dec96d1c9
--- /dev/null
+++ b/challenge-115/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2021/06/perl_weekly_challenge_week_115.html
diff --git a/challenge-115/jaldhar-h-vyas/perl/ch-1.pl b/challenge-115/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..eb9ba1fed0
--- /dev/null
+++ b/challenge-115/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+
+my (%first, %last);
+
+for my $arg (@ARGV) {
+ $first{substr($arg, 0, 1)} = 1;
+ $last{substr($arg, -1, 1)} = 1;
+}
+
+for my $key (keys %first) {
+ unless (exists $last{$key}) {
+ say 0;
+ exit;
+ }
+}
+say 1;
+
diff --git a/challenge-115/jaldhar-h-vyas/perl/ch-2.pl b/challenge-115/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..6b199b65ce
--- /dev/null
+++ b/challenge-115/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+
+my @N = sort { $b <=> $a } @ARGV;
+
+if ($N[-1] % 2 == 1) {
+ my $lasteven = -1;
+ while (defined $N[$lasteven] && $N[$lasteven] % 2 == 1) {
+ $lasteven--;
+ }
+
+ if (defined $N[$lasteven]) {
+ my $temp = $N[$lasteven];
+ splice @N, $lasteven, 1;
+ push @N, $temp;
+ } else {
+ $N[-1]--;
+ }
+}
+
+say join q{}, @N; \ No newline at end of file
diff --git a/challenge-115/jaldhar-h-vyas/raku/ch-1.raku b/challenge-115/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..4aac5f31df
--- /dev/null
+++ b/challenge-115/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/raku
+
+sub MAIN(*@args) {
+ my (%first, %last);
+
+ for @args -> $arg {
+ %first{$arg.substr(0, 1)} = True;
+ %last{$arg.substr(*-1, 1)} = True;
+ }
+
+ for %first.keys -> $key {
+ unless %last{$key}:exists {
+ say 0;
+ exit;
+ }
+ }
+ say 1;
+}
+
diff --git a/challenge-115/jaldhar-h-vyas/raku/ch-2.raku b/challenge-115/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..da4c34b6bc
--- /dev/null
+++ b/challenge-115/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/raku
+
+sub MAIN(*@args) {
+ my @N = @args.sort({$^b <=> $^a});
+
+ if @N[*-1] % 2 == 1 {
+ my $lasteven = 1;
+ while @N[*-$lasteven] !~~ Nil && @N[*-$lasteven] % 2 == 1 {
+ $lasteven++;
+ }
+
+ if @N[*-$lasteven] !~~ Nil {
+ my $temp = @N[*-$lasteven];
+ @N.splice(*-$lasteven, 1);
+ @N.push($temp);
+ } else {
+ @N[*-1]--;
+ }
+ }
+
+ @N.join.say;
+} \ No newline at end of file