aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-02 11:23:17 +0000
committerGitHub <noreply@github.com>2024-01-02 11:23:17 +0000
commit5840cb15f297b8f5a5cf446e730211f610661274 (patch)
treebea051bb21c68de40b81c30b638929ccf31cc1be
parent04c607810284ab5b9b261c29412d91c5e1ddbe5c (diff)
parent596de0ea2c425017f256fd383a0ec33d24bc2f29 (diff)
downloadperlweeklychallenge-club-5840cb15f297b8f5a5cf446e730211f610661274.tar.gz
perlweeklychallenge-club-5840cb15f297b8f5a5cf446e730211f610661274.tar.bz2
perlweeklychallenge-club-5840cb15f297b8f5a5cf446e730211f610661274.zip
Merge pull request #9340 from PerlBoy1967/branch-for-challenge-250
w250 - Task 1 & 2
-rwxr-xr-xchallenge-250/perlboy1967/perl/ch1.pl35
-rwxr-xr-xchallenge-250/perlboy1967/perl/ch2.pl39
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-250/perlboy1967/perl/ch1.pl b/challenge-250/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..b274434c8a
--- /dev/null
+++ b/challenge-250/perlboy1967/perl/ch1.pl
@@ -0,0 +1,35 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 250
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-250
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Smallest Index
+Submitted by: Mohammad S Anwar
+
+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.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0;
+
+use List::MoreUtils qw(first_index);
+
+sub smallestIndex (@ints) {
+ first_index { $_ % 10 == $_[$_] } 0 .. $#_;
+}
+
+is(smallestIndex(0,1,2),0);
+is(smallestIndex(4,3,2,1),2);
+is(smallestIndex(1,2,3,4,5,6,7,8,9,0),-1);
+
+done_testing;
diff --git a/challenge-250/perlboy1967/perl/ch2.pl b/challenge-250/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..3ece5664fe
--- /dev/null
+++ b/challenge-250/perlboy1967/perl/ch2.pl
@@ -0,0 +1,39 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 250
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-250
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Alphanumeric String Value
+Submitted by: Mohammad S Anwar
+
+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
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0;
+
+use List::Util qw(max);
+
+sub alphanumericStringValue (@strings) {
+ 0 + max map { /^\d+$/ ? $_ : length $_ } @_;
+}
+
+is(alphanumericStringValue(qw(perl 2 000 python r4ku)),6);
+is(alphanumericStringValue(qw(001 1 000 0001)),1);
+
+done_testing;