diff options
| -rw-r--r-- | challenge-207/zapwai/perl/ch-1.pl | 27 | ||||
| -rw-r--r-- | challenge-207/zapwai/perl/ch-2.pl | 18 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-207/zapwai/perl/ch-1.pl b/challenge-207/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..ba40593b13 --- /dev/null +++ b/challenge-207/zapwai/perl/ch-1.pl @@ -0,0 +1,27 @@ +use v5.30.0; +my @words = qw( Hello Alaska Dad Peace ); +#my @words = qw( OMG bye ); +my $str1 = 'qwertyuiop'; +my $str2 = 'asdfghjkl'; +my $str3 = 'zxcvbnm'; +my @onerows; +for my $word (@words) { + if (tally(lc $word) != 0) { + push @onerows, $word; + } +} +sub tally { + my $word = shift; + my ($t1, $t2, $t3); + foreach (split("",$word)) { + $t1++ if ($str1 =~ $_) ; + $t2++ if ($str2 =~ $_) ; + $t3++ if ($str3 =~ $_) ; + } + return 1 if ($t1 == length $word); + return 2 if ($t2 == length $word); + return 3 if ($t3 == length $word); + 0 +} +say "Input: \@words = (".join(", ",@words).")"; +say "Output: (".join(", ",@onerows).")"; diff --git a/challenge-207/zapwai/perl/ch-2.pl b/challenge-207/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..f48202b111 --- /dev/null +++ b/challenge-207/zapwai/perl/ch-2.pl @@ -0,0 +1,18 @@ +use v5.30.0; +#my @citations = (10,8,5,4,3); +my @citations = (25,8,5,3,3); + +my $h = 0; +for (1 .. $#citations + 1) { + $h++; + my $cnt; + for (@citations) { + $cnt++ if ($_ > $h); + } + next if ($cnt > $h); + last; +} + +say "Input: \@citations = (".join(", ",@citations).")"; +say "Output: $h"; + |
