aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-11-14 03:26:16 +0000
committerGitHub <noreply@github.com>2022-11-14 03:26:16 +0000
commitb4566a5534169bd77a54e66e7df86ee47e6c924e (patch)
tree0371252fe4d20b8e060f9627579eca7d782da0fc
parentc0d094277c8363c2de514ea38002875e417bd26d (diff)
parent41700d17d86014a7b61bdedb3e8dc9d676cd9683 (diff)
downloadperlweeklychallenge-club-b4566a5534169bd77a54e66e7df86ee47e6c924e.tar.gz
perlweeklychallenge-club-b4566a5534169bd77a54e66e7df86ee47e6c924e.tar.bz2
perlweeklychallenge-club-b4566a5534169bd77a54e66e7df86ee47e6c924e.zip
Merge pull request #7081 from jaldhar/challenge-190
Challenge 190 by Jaldhar H. Vyas.
-rw-r--r--challenge-190/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-190/jaldhar-h-vyas/perl/ch-1.pl11
-rwxr-xr-xchallenge-190/jaldhar-h-vyas/perl/ch-2.pl32
-rwxr-xr-xchallenge-190/jaldhar-h-vyas/raku/ch-1.raku16
-rwxr-xr-xchallenge-190/jaldhar-h-vyas/raku/ch-2.raku26
5 files changed, 86 insertions, 0 deletions
diff --git a/challenge-190/jaldhar-h-vyas/blog.txt b/challenge-190/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..7b707d5330
--- /dev/null
+++ b/challenge-190/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2022/11/perl_weekly_challenge_week_190.html \ No newline at end of file
diff --git a/challenge-190/jaldhar-h-vyas/perl/ch-1.pl b/challenge-190/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..956e2f3220
--- /dev/null
+++ b/challenge-190/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+my $s = shift // die "Need a string of upper or lower case letters!\n";
+
+say
+ $s =~ /^ [A-Z] [a-z]* $/x ||
+ $s =~ /^ [A-Z]* $/x ||
+ $s =~ /^ [a-z]* $/x
+? 1 : 0; \ No newline at end of file
diff --git a/challenge-190/jaldhar-h-vyas/perl/ch-2.pl b/challenge-190/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..adc8571881
--- /dev/null
+++ b/challenge-190/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+
+my $s = shift // die "Need a string of digits!\n";
+my @combos;
+
+push @combos, [ split //, $s ];
+if ((length $s) % 2) {
+ push @combos, [ $s =~ /(.) ([0-9]{2})+ /gx ];
+ push @combos, [ $s =~ /([0-9]{2})+ (.) /gx ];
+
+} else {
+ push @combos, [ $s =~ /([0-9]{2})/g ];
+}
+
+for my $n (0 .. (length $s) - 2) {
+ my @chars = split //, $s;
+ my $long = join q{}, @chars[$n, $n + 1];
+ splice @chars, $n, 2, $long;
+ push @combos, \@chars;
+}
+
+my %results;
+
+for my $combo (@combos) {
+ unless ( scalar grep { $_ < 1 || $_ > 26 } @{$combo}) {
+ $results{ join q{}, map { ('A' .. 'Z')[$_ -1] } @{$combo} }++;
+ }
+}
+
+say join q{, }, sort keys %results;
diff --git a/challenge-190/jaldhar-h-vyas/raku/ch-1.raku b/challenge-190/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..b470966676
--- /dev/null
+++ b/challenge-190/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ Str $s #= a string of upper or lower case letters
+) {
+ grammar Validator {
+ rule TOP { <capitalized> | <all-upper> | <all-lower> }
+ rule capitalized { <upper><all-lower> }
+ rule all-upper { <upper>+ }
+ rule all-lower { <lower>+ }
+ token upper { <[A .. Z]> }
+ token lower { <[a .. z]> }
+ }
+
+ say Validator.parse($s) ?? 1 !! 0;
+} \ No newline at end of file
diff --git a/challenge-190/jaldhar-h-vyas/raku/ch-2.raku b/challenge-190/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..6eda7283b3
--- /dev/null
+++ b/challenge-190/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/raku
+
+sub MAIN(
+ Str $s #= a string of digits
+) {
+ my @combos;
+
+ @combos.push($s.comb);
+ @combos.push($s.comb(2));
+
+ for 0 ..^ $s.chars - 1 -> $n {
+ my @chars = $s.comb;
+ @chars.splice($n, 2, @chars[$n,$n + 1].join);
+ @combos.push(@chars);
+ }
+
+ my %results;
+
+ for @combos -> $combo {
+ unless @$combo.grep({ $_ < 1 || $_ > 26 }).elems {
+ %results{$combo.map({ ('A' .. 'Z')[$_ -1] }).join}++;
+ }
+ }
+
+ %results.keys.sort.join(q{, }).say;
+} \ No newline at end of file