diff options
| -rw-r--r-- | challenge-216/zapwai/perl/ch-1.pl | 21 | ||||
| -rw-r--r-- | challenge-216/zapwai/perl/ch-2.pl | 32 |
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. |
