aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-07 21:06:46 +0000
committerGitHub <noreply@github.com>2024-01-07 21:06:46 +0000
commit6e40c5817bfea9672fc0211c264807fe70cbc2d6 (patch)
tree60bd7b0412837eaa9e53b3f4d3fdb0c261c6b9ab
parent385f1352d73d1deecbdec5691fc1ef4dc83ce831 (diff)
parentd85177484b45659b7eb779970aa7c65d2e794b4a (diff)
downloadperlweeklychallenge-club-6e40c5817bfea9672fc0211c264807fe70cbc2d6.tar.gz
perlweeklychallenge-club-6e40c5817bfea9672fc0211c264807fe70cbc2d6.tar.bz2
perlweeklychallenge-club-6e40c5817bfea9672fc0211c264807fe70cbc2d6.zip
Merge pull request #9358 from Solathian/branch-for-challenge-250
Added files
-rw-r--r--challenge-250/solathian/ch-1.pl31
-rw-r--r--challenge-250/solathian/ch-2.pl35
2 files changed, 66 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..56b7b9a2cf
--- /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..cd78bb7930
--- /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