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