From 0cf08a232b034272bb0bc4d4f69760f5547d68fd Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 7 Jul 2025 18:13:51 +0000 Subject: w329 - Task 1 & 2 --- challenge-329/perlboy1967/perl/ch1.pl | 32 +++++++++++++++++++++++++++++ challenge-329/perlboy1967/perl/ch2.pl | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 challenge-329/perlboy1967/perl/ch1.pl create mode 100755 challenge-329/perlboy1967/perl/ch2.pl diff --git a/challenge-329/perlboy1967/perl/ch1.pl b/challenge-329/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..66bd2f300b --- /dev/null +++ b/challenge-329/perlboy1967/perl/ch1.pl @@ -0,0 +1,32 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Counter Integers +Submitted by: Mohammad Sajid Anwar + +You are given a string containing only lower case English letters and digits. + +Write a script to replace every non-digit character with a space and then +return all the distinct integers left. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(uniq); + +sub countIntegers ($str) { + uniq $str =~ m#\d+#g; +} + +is([countIntegers('the1weekly2challenge2')],[1,2],'Example 1'); +is([countIntegers('go21od1lu5c7k')],[21,1,5,7],'Example 2'); +is([countIntegers('4p3e2r1l')],[4,3,2,1],'Example 3'); + +done_testing; diff --git a/challenge-329/perlboy1967/perl/ch2.pl b/challenge-329/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..6b0c08ea5e --- /dev/null +++ b/challenge-329/perlboy1967/perl/ch2.pl @@ -0,0 +1,38 @@ +#!/bin/perl + +=pod + +L + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Nice String +Submitted by: Mohammad Sajid Anwar + +You are given a string made up of lower and upper case English letters only. + +Write a script to return the longest substring of the give string which is +nice. A string is nice if, for every letter of the alphabet that the string +contains, it appears both in uppercase and lowercase. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(max); + +sub maxNiceStrings ($str) { + my @s; push(@s,$1) while ($str =~ /(([a-zA-Z])\2+)/ig); + my @n = grep { /[a-z]/ and /[A-Z]/ } @s; + my $maxLen = max(map { length } @n) // 0; + $maxLen ? grep { $maxLen == length } @n : (); +} + +is([maxNiceStrings('YaaAho')], ['aaA'], 'Example 1'); +is([maxNiceStrings('cC')], ['cC'], 'Example 2'); +is([maxNiceStrings('A')], [], 'Example 3'); +is([maxNiceStrings('YaaaHoO')], ['oO'], 'Own Example 1'); +is([maxNiceStrings('YaAaHooO')],['aAa','ooO'],'Own Example 2'); + +done_testing; -- cgit