From 596de0ea2c425017f256fd383a0ec33d24bc2f29 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Tue, 2 Jan 2024 09:14:12 +0000 Subject: w250 - Task 1 & 2 --- challenge-250/perlboy1967/perl/ch1.pl | 35 +++++++++++++++++++++++++++++++ challenge-250/perlboy1967/perl/ch2.pl | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 challenge-250/perlboy1967/perl/ch1.pl create mode 100755 challenge-250/perlboy1967/perl/ch2.pl 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; -- cgit