diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-07 20:30:27 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-07 20:30:27 +0000 |
| commit | e0c8fbbb25313832db7dd15206dc011a5f8581fc (patch) | |
| tree | 0eb78e97cec7914583c2e643bc1aae5ee0b99e28 | |
| parent | 9b09ab639f4d7c5cb7c16197c574e1cb8423775c (diff) | |
| parent | 71284c9a9f21186c637a988437c08d32bd1792eb (diff) | |
| download | perlweeklychallenge-club-e0c8fbbb25313832db7dd15206dc011a5f8581fc.tar.gz perlweeklychallenge-club-e0c8fbbb25313832db7dd15206dc011a5f8581fc.tar.bz2 perlweeklychallenge-club-e0c8fbbb25313832db7dd15206dc011a5f8581fc.zip | |
Merge pull request #9357 from E7-87-83/newt
Week 250
| -rw-r--r-- | challenge-250/cheok-yin-fung/perl/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-250/cheok-yin-fung/perl/ch-2.pl | 22 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-250/cheok-yin-fung/perl/ch-1.pl b/challenge-250/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..8316c395ee --- /dev/null +++ b/challenge-250/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,17 @@ +# The Weekly Challenge 250 +# Task 1 Smallest Index +use v5.30.0; +use warnings; + +sub si { + my @arr = @_; + for my $k (0..$#arr) { + return $k if $k == $arr[$k] % 10; + } + return -1; +} + +use Test::More tests=>3; +ok si(0, 1, 2) == 0; +ok si(4, 3, 2, 1) == 2; +ok si(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) == -1; diff --git a/challenge-250/cheok-yin-fung/perl/ch-2.pl b/challenge-250/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..729e601156 --- /dev/null +++ b/challenge-250/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,22 @@ +# The Weekly Challenge 250 +# Task 2 Alphanumeric String Value +use v5.30.0; +use warnings; +use List::Util qw/max/; + +sub asv { + my $word = $_[0]; + return $1 if $word =~ /^0*(\d+)$/; + return length $word; +} + +sub masv { + my @arr = @_; + return max map {asv $_} @arr; +} + + +use Test2::V0; +ok masv("perl", "2", "000", "python", "r4ku") == 6; +ok masv("001", "1", "000", "0001") == 1; +done_testing(); |
