aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2023-05-10 13:38:52 -0400
committerDavid Ferrone <zapwai@gmail.com>2023-05-10 13:38:52 -0400
commit470e27670b6a61e9851d4c1c66bb567b3d30af0d (patch)
treeabf575078741021b67a6d6328c0585a5dd1a387c
parent488c528fc8725f3e183eae4073709f95edca33fb (diff)
downloadperlweeklychallenge-club-470e27670b6a61e9851d4c1c66bb567b3d30af0d.tar.gz
perlweeklychallenge-club-470e27670b6a61e9851d4c1c66bb567b3d30af0d.tar.bz2
perlweeklychallenge-club-470e27670b6a61e9851d4c1c66bb567b3d30af0d.zip
Week 216
-rw-r--r--challenge-216/zapwai/perl/ch-1.pl21
-rw-r--r--challenge-216/zapwai/perl/ch-2.pl32
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-216/zapwai/perl/ch-1.pl b/challenge-216/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..24a43ebf36
--- /dev/null
+++ b/challenge-216/zapwai/perl/ch-1.pl
@@ -0,0 +1,21 @@
+use v5.30.0;
+my @words = ('abc', 'abcd', 'bcd');
+my $reg = "AB1 2CD";
+my @letters = split("",lc $reg);
+my @L;
+for (@letters) {
+ push @L, $_ if ($_ =~ m/[a-z]/);
+}
+my $len = $#L + 1;
+my $cnt;
+my @matches;
+foreach my $word (@words) {
+ $cnt = 0;
+ foreach my $letter (@L) {
+ $cnt++ if ($word =~ $letter);
+ push @matches, $word if ($cnt == $len);
+ }
+}
+say "Input: \@words = (" . join(",",@words) . "), \$reg = '$reg'";
+print "Output: ";
+say "(" . join(",",@matches) . ")";
diff --git a/challenge-216/zapwai/perl/ch-2.pl b/challenge-216/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..5514faeae1
--- /dev/null
+++ b/challenge-216/zapwai/perl/ch-2.pl
@@ -0,0 +1,32 @@
+use v5.30.0;
+my @stickers = ('perl','raku','python');my $word = 'peon';
+#my @stickers = ('love','hate','angry');my $word = 'goat';
+#my @stickers = ('come','nation','delta');my $word = 'accommodation';
+say "Input: \@stickers = (" . join(",", @stickers) . "), \$word = $word";
+print "Output: ";
+my @L = split("",$word);
+my %L;
+L: foreach my $l (@L) {
+ foreach (0 .. $#stickers) {
+
+ if ($stickers[$_] =~ /$l/) {
+ my $ind = $_ . $l;
+ $L{$ind}++;
+ next L;
+ }
+ }
+}
+my %bin;
+foreach (keys %L) {
+ my ($num, $let) = split("",$_);
+ $bin{$num} = $L{$_} if ($L{$_} > $bin{$num});
+# say "$_ $L{$_}";
+}
+my $tot;
+$tot += $bin{$_} for (0 .. $#stickers);
+say $tot;
+say "One solution is: ";
+foreach (0 .. $#stickers) {
+ say "$bin{$_} from '$stickers[$_]'" if ($bin{$_});
+}
+# Not the most efficient solution.