diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-02 23:18:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-02 23:18:43 +0100 |
| commit | 7d481b3b5c0f0a77da0c975ef42b0c47865ebce0 (patch) | |
| tree | 594ab29562986cd3bb677821b864d1536ff5d928 | |
| parent | 698c027e7ef73ac2753c97d4e64d7fba2b2ddc95 (diff) | |
| parent | 97f75e5e3dadf9b30b77c4aad2aa250ce8b4c68e (diff) | |
| download | perlweeklychallenge-club-7d481b3b5c0f0a77da0c975ef42b0c47865ebce0.tar.gz perlweeklychallenge-club-7d481b3b5c0f0a77da0c975ef42b0c47865ebce0.tar.bz2 perlweeklychallenge-club-7d481b3b5c0f0a77da0c975ef42b0c47865ebce0.zip | |
Merge pull request #12450 from Solathian/branch-for-challenge-332
Branch for challenge 332
| -rw-r--r-- | challenge-250/solathian/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-250/solathian/ch-2.pl | 35 | ||||
| -rw-r--r-- | challenge-332/solathian/perl/ch-1.pl | 11 | ||||
| -rw-r--r-- | challenge-332/solathian/perl/ch-2.pl | 20 |
4 files changed, 97 insertions, 0 deletions
diff --git a/challenge-250/solathian/ch-1.pl b/challenge-250/solathian/ch-1.pl new file mode 100644 index 0000000000..229535f1b1 --- /dev/null +++ b/challenge-250/solathian/ch-1.pl @@ -0,0 +1,31 @@ +#!usr/bin/perl +use v5.38; +use builtin qw(indexed); +no warnings "experimental"; + + +# Challenge 250 - 1 - Smallest Index +# 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. + + +small(0,1,2); # 0 +small(4, 3, 2, 1); # 2 +small(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); # -1 + +sub small(@array) +{ + my $returnVal = -1; + + foreach my ($index, $elem) (indexed @array) + { + if($index % 10 == $elem) + { + $returnVal = $index; + last; + } + } + + say $returnVal; + return $returnVal; +}
\ No newline at end of file diff --git a/challenge-250/solathian/ch-2.pl b/challenge-250/solathian/ch-2.pl new file mode 100644 index 0000000000..052fffe081 --- /dev/null +++ b/challenge-250/solathian/ch-2.pl @@ -0,0 +1,35 @@ +#!usr/bin/perl +use v5.38; + +# Challenge 250 - 2 - Alphanumeric String Value +# 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 + + +asv("perl", "2", "000", "python", "r4ku"); +asv("001", "1", "000", "0007"); + + +sub asv(@list) +{ + my $max = 0; + + foreach my $elem (@list) + { + # if it only has numbers + if($elem =~ m"^\d+$") + { + $max = eval $elem if( $elem > $max ); + } + else + { + $max = length $elem if( length $elem > $max ); + } + } + + say $max; +}
\ No newline at end of file diff --git a/challenge-332/solathian/perl/ch-1.pl b/challenge-332/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..6fa2f460ba --- /dev/null +++ b/challenge-332/solathian/perl/ch-1.pl @@ -0,0 +1,11 @@ +use v5.40; +use List::Util qw(all); + +binaryDate("2025-07-26"); # "11111101001-111-11010" +binaryDate("2000-02-02"); # "11111010000-10-10" +binaryDate("2024-12-31"); # "11111101000-1100-11111" + +sub binaryDate($string) # it is assumed that the string is already of the correct format and is a valid date +{ + say join('-', map{sprintf("%b", $_)} split('-', $string)); +}
\ No newline at end of file diff --git a/challenge-332/solathian/perl/ch-2.pl b/challenge-332/solathian/perl/ch-2.pl new file mode 100644 index 0000000000..b888320e4c --- /dev/null +++ b/challenge-332/solathian/perl/ch-2.pl @@ -0,0 +1,20 @@ +use v5.40; +use List::Util qw(all); + +isOdd("weekly"); # false +isOdd("challenge"); # false +isOdd("perl"); # true +isOdd("perl112"); # true +isOdd(""); # true + + + +sub isOdd($string) +{ + my %hash; + + $string =~ s/[^a-z]//gi; # remove everything which is not between 'a' and 'z', since it only mentioned letters + $hash{$_}++ foreach (split('', $string)); + ((all{$_ % 2 != 0} values %hash) and (scalar values %hash > 0)) ? say 'true' : say 'false'; +} + |
