diff options
| -rw-r--r-- | challenge-282/cheok-yin-fung/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-282/cheok-yin-fung/perl/ch-2.pl | 19 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-282/cheok-yin-fung/perl/ch-1.pl b/challenge-282/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..29083e409e --- /dev/null +++ b/challenge-282/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,15 @@ +# The Weekly Challenge 282 +# Task 1 Good Integer +use v5.30.0; +use warnings; + +sub gi { + my $int = $_[0]; + return -1 if $int =~ /(\d)\1\1\1/; + return $1 x 3 if $int =~ /(\d)\1\1/; +} + +use Test::More tests=>3; +ok gi("12344456") eq "444"; +ok gi("1233334") eq -1; +ok gi("1020003") eq "000"; diff --git a/challenge-282/cheok-yin-fung/perl/ch-2.pl b/challenge-282/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..ed2afa15b3 --- /dev/null +++ b/challenge-282/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,19 @@ +# The Weekly Challenge 282 +# Task 2 Changing Keys +use v5.30.0; +use warnings; +use List::Util qw/reduce/; + +sub ck { + my $str = $_[0]; + return 0 if $str eq ""; + $str = lc $str; + my @alphabets = split "", $str; + my $abc = reduce { substr($a,-1) eq $b ? $a : $a.$b } @alphabets; + return ((length $abc) - 1); +} + +use Test::More tests=>3; +ok ck("pPeERrLl") == 3; +ok ck("rRr") == 0; +ok ck("GoO") == 1; |
