diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-08 00:16:27 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-08 00:16:27 +0000 |
| commit | 051d2c18ad69faedcd19a1f46bc92e30e7d31fce (patch) | |
| tree | 99c68c0ad5db38aac7f9502da049685a3b7a70c9 | |
| parent | c98a4e4ddcdf0973f3457f2e08ebc1e871e4f50f (diff) | |
| parent | efa63f1e945ece71c7b567c7726bf9bda4381c0d (diff) | |
| download | perlweeklychallenge-club-051d2c18ad69faedcd19a1f46bc92e30e7d31fce.tar.gz perlweeklychallenge-club-051d2c18ad69faedcd19a1f46bc92e30e7d31fce.tar.bz2 perlweeklychallenge-club-051d2c18ad69faedcd19a1f46bc92e30e7d31fce.zip | |
Merge pull request #9364 from adamcrussell/challenge-250
initial commit
| -rw-r--r-- | challenge-250/adam-russell/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-250/adam-russell/perl/ch-2.pl | 21 |
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-250/adam-russell/perl/ch-1.pl b/challenge-250/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..ec93d48b23 --- /dev/null +++ b/challenge-250/adam-russell/perl/ch-1.pl @@ -0,0 +1,19 @@ +use v5.38; +## +# You are given an array of integers, @ints. +# Write a script to find the smallest index i such that +# i mod 10 == $ints[i] +# otherwise return -1. +## +sub smallest_index{ + do{ + return $_ if $_ % 10 == $_[$_]; + } for 0 .. @_ - 1; + return -1; +} + +MAIN:{ + say smallest_index 0, 1, 2; + say smallest_index 4, 3, 2, 1; + say smallest_index 1, 2, 3, 4, 5, 6, 7, 8, 9, 0; +} diff --git a/challenge-250/adam-russell/perl/ch-2.pl b/challenge-250/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..5aa996c60d --- /dev/null +++ b/challenge-250/adam-russell/perl/ch-2.pl @@ -0,0 +1,21 @@ + + +use v5.38; +## +# You are given an array of alphanumeric strings. +# Write a script to return the maximum value of alphanumeric string in the given array. +# The value of alphanumeric string can be defined as +# a) The numeric representation of the string in base 10 if it is made up of digits only. +# b) otherwise the length of the string +## +sub alphanumeric_string_value{ + my @values = sort {$b <=> $a} map{ + /^\d*$/?0 + $_:length + } @_; + return $values[0]; +} + +MAIN:{ + say alphanumeric_string_value qw/perl 2 000 python r4ku/; + say alphanumeric_string_value qw/001 1 000 0001/; +} |
