diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-24 22:22:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-24 22:22:38 +0100 |
| commit | 2238c4c5cca4d1e4ac7a607cba7b764ab3f73279 (patch) | |
| tree | fbf3065d140e36da1726599ee84a000939f1beeb | |
| parent | cf22933c7cf9fc65aea34cd7c73d15051dffd404 (diff) | |
| parent | bfd1832bbbda9d5b99459af6bf5a28e180316a99 (diff) | |
| download | perlweeklychallenge-club-2238c4c5cca4d1e4ac7a607cba7b764ab3f73279.tar.gz perlweeklychallenge-club-2238c4c5cca4d1e4ac7a607cba7b764ab3f73279.tar.bz2 perlweeklychallenge-club-2238c4c5cca4d1e4ac7a607cba7b764ab3f73279.zip | |
Merge pull request #10312 from PerlBoy1967/branch-for-challenge-275
w275 - Task 1 & 2
| -rwxr-xr-x | challenge-275/perlboy1967/perl/ch1.pl | 35 | ||||
| -rwxr-xr-x | challenge-275/perlboy1967/perl/ch2.pl | 41 |
2 files changed, 76 insertions, 0 deletions
diff --git a/challenge-275/perlboy1967/perl/ch1.pl b/challenge-275/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..624b8fb931 --- /dev/null +++ b/challenge-275/perlboy1967/perl/ch1.pl @@ -0,0 +1,35 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 275 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-275 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Broken Keys +Submitted by: Mohammad Sajid Anwar + +You are given a sentence, $sentence and list of broken keys @keys. + +Write a script to find out how many words can be typed fully. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Test2::V0 qw(-no_srand); + +sub brokenKeys ($sentence,@keys) { + my $re = '['.join('',@keys).']'; + scalar grep !/$re/i, split /\s+/, $sentence; +} + +is(brokenKeys('Perl Weekly Challenge','l','a'),0); +is(brokenKeys('Perl and Raku','a'),1); +is(brokenKeys('Well done Team PWC','l','o'),2); +is(brokenKeys('The joys of polyglottism','T'),2); + +done_testing; diff --git a/challenge-275/perlboy1967/perl/ch2.pl b/challenge-275/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..ccd347c497 --- /dev/null +++ b/challenge-275/perlboy1967/perl/ch2.pl @@ -0,0 +1,41 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 275 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-275 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Replace Digits +Submitted by: Mohammad Sajid Anwar + +You are given an alphanumeric string, $str, where each character +is either a letter or a digit. + +Write a script to replace each digit in the given string with the +value of the previous letter plus (digit) places. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Test2::V0 qw(-no_srand); + +sub replaceDigits ($str) { + my $r; + while ($str =~ s#^(?<c>[a-z])(?<d>\d+)##i) { + $r .= $+{c} . join('', map { chr(ord($+{c})+$_) } split(//,$+{d})); + } + return $r.$str; +} + +is(replaceDigits('a1c1e1'),'abcdef','Example 1'); +is(replaceDigits('a1b2c3d4'),'abbdcfdh','Example 2'); +is(replaceDigits('b2b'),'bdb','Example 3'); +is(replaceDigits('a16z'),'abgz','Example 4'); +is(replaceDigits('Z5'),'Z_','Own test'); + +done_testing; |
