aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2024-01-02 09:14:12 +0000
committerNiels van Dijke <perlboy@cpan.org>2024-01-02 09:14:12 +0000
commit596de0ea2c425017f256fd383a0ec33d24bc2f29 (patch)
treead937f6f9b3eb2e7acd82b032c27a1980a7f1176
parent5f38c976cae9103ec02e413224d047d8b149956d (diff)
downloadperlweeklychallenge-club-596de0ea2c425017f256fd383a0ec33d24bc2f29.tar.gz
perlweeklychallenge-club-596de0ea2c425017f256fd383a0ec33d24bc2f29.tar.bz2
perlweeklychallenge-club-596de0ea2c425017f256fd383a0ec33d24bc2f29.zip
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;