aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-05-11 23:02:01 +0100
committerGitHub <noreply@github.com>2023-05-11 23:02:01 +0100
commit45235eeeec3da08f107722ce4e400358026ccbba (patch)
tree63d63ecc53120afbb99ca42343557ce27fc2ebe9
parent6b49a60079b5b54288d9418ab7da45e8660d8c65 (diff)
parent470e27670b6a61e9851d4c1c66bb567b3d30af0d (diff)
downloadperlweeklychallenge-club-45235eeeec3da08f107722ce4e400358026ccbba.tar.gz
perlweeklychallenge-club-45235eeeec3da08f107722ce4e400358026ccbba.tar.bz2
perlweeklychallenge-club-45235eeeec3da08f107722ce4e400358026ccbba.zip
Merge pull request #8053 from zapwai/branch-for-216
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.