diff options
| -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; |
