aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2025-05-12 12:16:14 -0400
committerGitHub <noreply@github.com>2025-05-12 12:16:14 -0400
commite806b77af6e891e0e75be91a787c7d896ccfed2e (patch)
tree52d6a0deeaab1e24af68d241ea7f9c09c76faf16
parent62f1ccaddfc5a65501df9cfdf528d28927fef410 (diff)
downloadperlweeklychallenge-club-e806b77af6e891e0e75be91a787c7d896ccfed2e.tar.gz
perlweeklychallenge-club-e806b77af6e891e0e75be91a787c7d896ccfed2e.tar.bz2
perlweeklychallenge-club-e806b77af6e891e0e75be91a787c7d896ccfed2e.zip
Week 321
-rw-r--r--challenge-321/zapwai/perl/ch-1.pl22
-rw-r--r--challenge-321/zapwai/perl/ch-2.pl33
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-321/zapwai/perl/ch-1.pl b/challenge-321/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..1c6fd48c24
--- /dev/null
+++ b/challenge-321/zapwai/perl/ch-1.pl
@@ -0,0 +1,22 @@
+use feature qw(signatures say);
+
+sub proc(@n) {
+ say "Input: \@n = @n";
+ @n = sort {$a <=> $b} @n;
+ my @dist;
+ do {
+ my $min = shift @n;
+ my $max = pop @n;
+ my $avg = ($max + $min) / 2;
+ push @dist, $avg unless (grep {$_ == $avg} @dist);
+ last if (@n == 1);
+ } while (@n);
+ say "Output: ", scalar @dist;
+}
+
+my @nums = (1, 2, 4, 3, 5, 6);
+proc(@nums);
+@nums = (0, 2, 4, 8, 3, 5);
+proc(@nums);
+@nums = (7, 3, 1, 0, 5, 9);
+proc(@nums);
diff --git a/challenge-321/zapwai/perl/ch-2.pl b/challenge-321/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..5842417135
--- /dev/null
+++ b/challenge-321/zapwai/perl/ch-2.pl
@@ -0,0 +1,33 @@
+use feature qw(signatures say);
+
+sub p($s) {
+ my @d = split '', $s;
+ my @o;
+ for (@d) {
+ if ($_ eq '#') {
+ pop @o;
+ } else {
+ push @o, $_;
+ }
+ }
+ return join '', @o;
+}
+
+sub proc($str1, $str2) {
+ say "Input: $str1, $str2";
+ my $s1 = p($str1);
+ my $s2 = p($str2);
+ say "Output: ", ($s1 eq $s2) ? 'true' : 'false';
+}
+
+$str1 = "ab#c";
+$str2 = "ad#c";
+proc($str1, $str2);
+
+$str1 = "ab##";
+$str2 = "a#b#";
+proc($str1, $str2);
+
+$str1 = "a#b";
+$str2 = "c";
+proc($str1, $str2);