diff options
| author | Adam Russell <ac.russell@live.com> | 2024-01-07 18:52:20 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2024-01-07 18:52:20 -0500 |
| commit | efa63f1e945ece71c7b567c7726bf9bda4381c0d (patch) | |
| tree | bfbdb449840d2a3555b16070e5b573656c576b03 | |
| parent | 35cd0ec65acdd3a2c925c3a5d3a193bd307cdc5a (diff) | |
| download | perlweeklychallenge-club-efa63f1e945ece71c7b567c7726bf9bda4381c0d.tar.gz perlweeklychallenge-club-efa63f1e945ece71c7b567c7726bf9bda4381c0d.tar.bz2 perlweeklychallenge-club-efa63f1e945ece71c7b567c7726bf9bda4381c0d.zip | |
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/; +} |
