diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-11-24 14:43:28 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-24 14:43:28 +0000 |
| commit | 28353531d5b2a7a78aa4f934f35f3cfd7399df0a (patch) | |
| tree | 16858a116dd2b32a38977f37ade54008fe94d252 | |
| parent | efe987cebff7d93e185a4cd17c23d6f4a7c7d3c3 (diff) | |
| parent | e2238db16053649a0e1aaa3e14a37813ad685263 (diff) | |
| download | perlweeklychallenge-club-28353531d5b2a7a78aa4f934f35f3cfd7399df0a.tar.gz perlweeklychallenge-club-28353531d5b2a7a78aa4f934f35f3cfd7399df0a.tar.bz2 perlweeklychallenge-club-28353531d5b2a7a78aa4f934f35f3cfd7399df0a.zip | |
Merge pull request #13077 from PerlBoy1967/branch-for-challenge-349
w349 - Task 1 & 2 (Perl)
| -rwxr-xr-x | challenge-349/perlboy1967/perl/ch1.pl | 36 | ||||
| -rwxr-xr-x | challenge-349/perlboy1967/perl/ch2.pl | 37 |
2 files changed, 73 insertions, 0 deletions
diff --git a/challenge-349/perlboy1967/perl/ch1.pl b/challenge-349/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..61f9803abc --- /dev/null +++ b/challenge-349/perlboy1967/perl/ch1.pl @@ -0,0 +1,36 @@ +#!/bin/perl + +=pod + +L<https://theweeklychallenge.org/blog/perl-weekly-challenge-349#TASK1> + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Power String +Submitted by: Mohammad Sajid Anwar + +You are given a string. + +Write a script to return the power of the given string. + +|| The power of the string is the maximum length of a non-empty substring +|| that contains only one unique character. + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use List::Util qw(max); + +sub powerString ($str) { + max map { length } $str =~ /((.)\2*)/g; +} + +is(powerString('textbook'),2,'Example 1'); +is(powerString('aaaaa'),5,'Example 2'); +is(powerString('hoorayyy'),3,'Example 3'); +is(powerString('x'),1,'Example 4'); +is(powerString('aabcccddeeffffghijjk'),4,'Example 5'); + +done_testing; diff --git a/challenge-349/perlboy1967/perl/ch2.pl b/challenge-349/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..98ba31ac6a --- /dev/null +++ b/challenge-349/perlboy1967/perl/ch2.pl @@ -0,0 +1,37 @@ +#!/bin/perl + +=pod + +L<https://theweeklychallenge.org/blog/perl-weekly-challenge-349#TASK2> + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Meeting Point +Submitted by: Mohammad Sajid Anwar + +You are given instruction string made up of U (up), D (down), L (left) and R (right). + +Write a script to return true if following the instruction, you meet the starting point (0,0). + +=cut + +use Test2::V0 qw(-no_srand); +use exact 'v5.32', -signatures; + +use boolean; +use List::MoreUtils qw(uniq); + +sub meetingPoint ($path) { + my %f = qw(L 0 R 0 U 0 D 0); + $f{$_}++ for (split//,$path); + boolean (($f{U} == $f{D}) and ($f{R} == $f{L})); +} + +is(meetingPoint('ULD'),false,'Example 1'); +is(meetingPoint('ULDR'),true,'Example 2'); +is(meetingPoint('UUURRRDDD'),false,'Example 3'); +is(meetingPoint('UURRRDDLLL'),true,'Example 4'); +is(meetingPoint('RRUULLDDRRUU'),false,'Example 5'); +is(meetingPoint('RDRUULLD'),true,'Own Example'); + +done_testing; |
