diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-08 17:02:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-08 17:02:48 +0100 |
| commit | 300c2f7a1732ba0a8bb98f03deaee37b51f2c312 (patch) | |
| tree | ad36124a67a5e66849f04724e9359f00dab35ec2 | |
| parent | d898d24c7333d65293bd12035d7fc37e551b9f9e (diff) | |
| parent | 0cf08a232b034272bb0bc4d4f69760f5547d68fd (diff) | |
| download | perlweeklychallenge-club-300c2f7a1732ba0a8bb98f03deaee37b51f2c312.tar.gz perlweeklychallenge-club-300c2f7a1732ba0a8bb98f03deaee37b51f2c312.tar.bz2 perlweeklychallenge-club-300c2f7a1732ba0a8bb98f03deaee37b51f2c312.zip | |
Merge pull request #12306 from PerlBoy1967/branch-for-challenge-329
w329 - Task 1 & 2
| -rwxr-xr-x | challenge-329/perlboy1967/perl/ch1.pl | 32 | ||||
| -rwxr-xr-x | challenge-329/perlboy1967/perl/ch2.pl | 38 |
2 files changed, 70 insertions, 0 deletions
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<https://theweeklychallenge.org/blog/perl-weekly-challenge-329#TASK1> + +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<https://theweeklychallenge.org/blog/perl-weekly-challenge-329#TASK2> + +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; |
