aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-225/zapwai/perl/ch-1.pl12
-rw-r--r--challenge-225/zapwai/perl/ch-2.pl30
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-225/zapwai/perl/ch-1.pl b/challenge-225/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..79c7ae9c82
--- /dev/null
+++ b/challenge-225/zapwai/perl/ch-1.pl
@@ -0,0 +1,12 @@
+use v5.30;
+my @list = ("Perl and Raku belong to the same family.",
+ "I love Perl.",
+ "The Perl and Raku Conference.");
+my $max = 0;
+for my $sent (@list) {
+ my @L = split(" ", $sent);
+ my $c = @L;
+ $max = $c if ($c > $max);
+}
+say "Input: \@list = @list";
+say "Output: $max";
diff --git a/challenge-225/zapwai/perl/ch-2.pl b/challenge-225/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..5a75e90c27
--- /dev/null
+++ b/challenge-225/zapwai/perl/ch-2.pl
@@ -0,0 +1,30 @@
+use v5.30;
+my @ints = (10, 4, 8, 3);
+#my @ints = (1,2,3,4,5);
+my @left = left(@ints);
+my @right = right(@ints);
+my @diff;
+push @diff, abs $left[$_] - $right[$_] for (0 .. $#left);
+say "Input: \@ints = @ints";
+say "Output: @diff";
+say "\t\@left = @left";
+say "\t\@right = @right";
+say "\t\@diff = @diff";
+sub left {
+ my @ints = @_;
+ pop @ints;
+ my @R = (0);
+ foreach (@ints) {
+ push @R, $R[-1] + $_;
+ }
+ return @R;
+}
+sub right {
+ my @ints = @_;
+ shift @ints;
+ my @R = (0);
+ foreach (reverse @ints) {
+ unshift @R, $R[0] + $_;
+ }
+ return @R;
+}