diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2022-11-13 18:43:16 -0500 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2022-11-13 18:43:16 -0500 |
| commit | 41700d17d86014a7b61bdedb3e8dc9d676cd9683 (patch) | |
| tree | b54d3a6361f175cfbcace662e0c46f31061179e1 | |
| parent | a3a5e396592490fe027c858ba2029afc1b98f0ce (diff) | |
| download | perlweeklychallenge-club-41700d17d86014a7b61bdedb3e8dc9d676cd9683.tar.gz perlweeklychallenge-club-41700d17d86014a7b61bdedb3e8dc9d676cd9683.tar.bz2 perlweeklychallenge-club-41700d17d86014a7b61bdedb3e8dc9d676cd9683.zip | |
Challenge 190 by Jaldhar H. Vyas.
| -rw-r--r-- | challenge-190/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-190/jaldhar-h-vyas/perl/ch-1.pl | 11 | ||||
| -rwxr-xr-x | challenge-190/jaldhar-h-vyas/perl/ch-2.pl | 32 | ||||
| -rwxr-xr-x | challenge-190/jaldhar-h-vyas/raku/ch-1.raku | 16 | ||||
| -rwxr-xr-x | challenge-190/jaldhar-h-vyas/raku/ch-2.raku | 26 |
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 |
