aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2025-07-08 07:21:54 -0400
committerGitHub <noreply@github.com>2025-07-08 07:21:54 -0400
commit5cef20c323b762902dacac11956ffccdb338a995 (patch)
tree029c76a8af04882bbfc8f67456ea13d3e4464e13
parentbd7fce4bd5d085c209a213f2daca1e79799c9e87 (diff)
downloadperlweeklychallenge-club-5cef20c323b762902dacac11956ffccdb338a995.tar.gz
perlweeklychallenge-club-5cef20c323b762902dacac11956ffccdb338a995.tar.bz2
perlweeklychallenge-club-5cef20c323b762902dacac11956ffccdb338a995.zip
Week 329
-rw-r--r--challenge-329/zapwai/perl/ch-1.pl27
-rw-r--r--challenge-329/zapwai/perl/ch-2.pl49
2 files changed, 76 insertions, 0 deletions
diff --git a/challenge-329/zapwai/perl/ch-1.pl b/challenge-329/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..548f812a24
--- /dev/null
+++ b/challenge-329/zapwai/perl/ch-1.pl
@@ -0,0 +1,27 @@
+use v5.38;
+use List::Util qw( uniq );
+
+sub proc($str) {
+ say "Input: $str";
+ my @l = split '', $str;
+ for my $i (0 .. $#l) {
+ if ($l[$i] =~ /[a-zA-Z]/) {
+ $l[$i] = ' ';
+ }
+ }
+ my $s = join '', @l;
+ $s =~ s/ +/ /;
+ my @o = split " ", $s;
+ my @u = uniq(@o);
+ say "Output: @u";
+}
+
+
+my $str = "the1weekly2challenge2";
+proc($str);
+
+$str = "go21od1lu5c7k";
+proc($str);
+
+$str = "4p3e2r1l";
+proc($str);
diff --git a/challenge-329/zapwai/perl/ch-2.pl b/challenge-329/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..72816b6d20
--- /dev/null
+++ b/challenge-329/zapwai/perl/ch-2.pl
@@ -0,0 +1,49 @@
+use v5.38;
+
+sub proc($str) {
+ say " Input: $str";
+ my @chunks;
+ my $on = 0;
+ my @l = split '', $str;
+ my $strip;
+ for my $i (0 .. $#l - 1) {
+ if (lc($l[$i]) eq lc($l[$i+1])) {
+ if ($on == 1) {
+ $strip .= $l[$i+1];
+ } else {
+ $on = 1;
+ $strip = $l[$i].$l[$i+1];
+ }
+ } else {
+ if ($on == 1) {
+ $on = 0;
+ push @chunks, $strip;
+ $strip = '';
+ }
+ }
+ }
+ if ($strip && $on) {
+ push @chunks, $strip;
+ }
+ print "Output: ";
+ if (@chunks) {
+ my ($max, $max_index) = (0, 0);
+ for my $i (0 .. $#chunks) {
+ if ($max < length $chunks[$i]) {
+ $max = length $chunks[$i];
+ $max_index = $i;
+ }
+ }
+ print $chunks[$max_index];
+ }
+ print "\n";
+}
+
+my $str = "YaaAho";
+proc($str);
+
+$str = "cC";
+proc($str);
+
+$str = "A";
+proc($str);