diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2025-05-10 23:21:55 -0400 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2025-05-11 17:39:04 -0400 |
| commit | 12de9b423880f6091475ecf57d1c16372313908c (patch) | |
| tree | c12792909d155cb1f1d7c0a8004f8db5eaabe1a6 | |
| parent | 47f59589cf7e6a3a951ebb63f871c1791441f853 (diff) | |
| download | perlweeklychallenge-club-12de9b423880f6091475ecf57d1c16372313908c.tar.gz perlweeklychallenge-club-12de9b423880f6091475ecf57d1c16372313908c.tar.bz2 perlweeklychallenge-club-12de9b423880f6091475ecf57d1c16372313908c.zip | |
Challenge 318 by Jaldhar H. Vyas.
| -rw-r--r-- | challenge-318/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-318/jaldhar-h-vyas/perl/ch-1.pl | 6 | ||||
| -rwxr-xr-x | challenge-318/jaldhar-h-vyas/perl/ch-2.pl | 22 | ||||
| -rwxr-xr-x | challenge-318/jaldhar-h-vyas/raku/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-318/jaldhar-h-vyas/raku/ch-2.raku | 24 |
5 files changed, 56 insertions, 0 deletions
diff --git a/challenge-318/jaldhar-h-vyas/blog.txt b/challenge-318/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..2b8060add7 --- /dev/null +++ b/challenge-318/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2025/05/perl_weekly_challenge_week_318.html diff --git a/challenge-318/jaldhar-h-vyas/perl/ch-1.pl b/challenge-318/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..46014198e4 --- /dev/null +++ b/challenge-318/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use v5.38; + +my ($str) = @ARGV; +my @groups = grep { length != 1 } ($str =~ /((.)(?:\2{2,}))/gmx); +say @groups ? (join q{, }, map { "\"$_\"" } @groups) : q{""}; diff --git a/challenge-318/jaldhar-h-vyas/perl/ch-2.pl b/challenge-318/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..3d967e5667 --- /dev/null +++ b/challenge-318/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use v5.38; +use builtin qw/ true false /; +no warnings 'experimental::builtin'; + +my @source = split /\s+/, shift; +my @target = split /\s+/, shift; +my $result = false; + +TOP: for my $i (0 .. scalar @source - 1) { + for my $j ($i .. scalar @source - 1) { + my @temp = @source; + splice @temp, $i, $j - $i + 1, reverse @temp[$i..$j]; + + if ((join q{}, @temp) eq (join q{}, @target)) { + $result = true; + last TOP; + } + } +} + +say $result ? 'true' : 'false'; diff --git a/challenge-318/jaldhar-h-vyas/raku/ch-1.sh b/challenge-318/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..3b2739a2e4 --- /dev/null +++ b/challenge-318/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e 'say (@*ARGS[0].match(/(.)$0**2..*/,:g)).map({"\"$_\""}).join(", ")||q{""}' "$@" diff --git a/challenge-318/jaldhar-h-vyas/raku/ch-2.raku b/challenge-318/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..06c78107e8 --- /dev/null +++ b/challenge-318/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,24 @@ +#!/usr/bin/raku + +sub MAIN( + Str $str1, + Str $str2 +) { + my @source = $str1.words; + my @target = $str2.words; + my $result = False; + + TOP: for 0 ..^ @source.elems -> $i { + for $i ..^ @source.elems -> $j { + my @temp = @source; + @temp.splice($i, $j - $i + 1, @temp[$i..$j].reverse); + + if @temp.join eq @target.join { + $result = True; + last TOP; + } + } + } + + say $result; +}
\ No newline at end of file |
