diff options
| author | David Ferrone <zapwai@gmail.com> | 2023-07-10 11:37:46 -0400 |
|---|---|---|
| committer | David Ferrone <zapwai@gmail.com> | 2023-07-10 11:37:46 -0400 |
| commit | 8e2b8846bba0cfe40014305a690daceb23e206e2 (patch) | |
| tree | f905e0135b2c35cf3d0e6548243716111d27a4e1 | |
| parent | 80e57ec8f3de321e2f66184490f16b335a281896 (diff) | |
| download | perlweeklychallenge-club-8e2b8846bba0cfe40014305a690daceb23e206e2.tar.gz perlweeklychallenge-club-8e2b8846bba0cfe40014305a690daceb23e206e2.tar.bz2 perlweeklychallenge-club-8e2b8846bba0cfe40014305a690daceb23e206e2.zip | |
Week 225
| -rw-r--r-- | challenge-225/zapwai/perl/ch-1.pl | 12 | ||||
| -rw-r--r-- | challenge-225/zapwai/perl/ch-2.pl | 30 |
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; +} |
