diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-09-29 13:25:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-29 13:25:19 +0100 |
| commit | c3e4a018d6e0af922853a0910b1a780a3e419c4f (patch) | |
| tree | 7ddc9f79ec341f9041fededf1a335826426464dd | |
| parent | ad6e8f2d20ca54b124b1fb1341f03755080fa6da (diff) | |
| parent | f5b63dee409f43f14c8d97e1e308bb13761567e8 (diff) | |
| download | perlweeklychallenge-club-c3e4a018d6e0af922853a0910b1a780a3e419c4f.tar.gz perlweeklychallenge-club-c3e4a018d6e0af922853a0910b1a780a3e419c4f.tar.bz2 perlweeklychallenge-club-c3e4a018d6e0af922853a0910b1a780a3e419c4f.zip | |
Merge pull request #12759 from pjcs00/wk341
Week 341 - Broken keys and mixed up words
| -rw-r--r-- | challenge-341/peter-campbell-smith/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-341/peter-campbell-smith/perl/ch-1.pl | 36 | ||||
| -rwxr-xr-x | challenge-341/peter-campbell-smith/perl/ch-2.pl | 35 |
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-341/peter-campbell-smith/blog.txt b/challenge-341/peter-campbell-smith/blog.txt new file mode 100644 index 0000000000..412832778e --- /dev/null +++ b/challenge-341/peter-campbell-smith/blog.txt @@ -0,0 +1 @@ +http://ccgi.campbellsmiths.force9.co.uk/challenge/341 diff --git a/challenge-341/peter-campbell-smith/perl/ch-1.pl b/challenge-341/peter-campbell-smith/perl/ch-1.pl new file mode 100755 index 0000000000..ee198d597d --- /dev/null +++ b/challenge-341/peter-campbell-smith/perl/ch-1.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge + +use v5.26; # The Weekly Challenge - 2025-09-29 +use utf8; # Week 341 - task 1 - Broken keyboard +use warnings; # Peter Campbell Smith + +binmode STDOUT, ':utf8'; +use Encode; + +broken_keyboard('Hello world', ['d']); +broken_keyboard('apple banana cherry', ['a', 'e']); +broken_keyboard('Coding is fun', []); +broken_keyboard('Perl and Python', ['p']); +broken_keyboard('aaaaa ccc b', ['a', 'b']); + +sub broken_keyboard { + + my ($string, $keys, $count); + + # initialise and concatenate broken keys + no warnings 'uninitialized'; + $string = $_[0]; + $keys .= $_ for @{$_[1]}; + + # delete words containing broken keys + $string =~ s|\w*[$keys]\w*||gi if $keys; + + # count the remaining words + $count ++ while $string =~ m|\w+|gi; + + # report + say qq[\nInput: \$string = '$_[0]', \@keys = ('] . join(q[', '], @{$_[1]}) . q[')]; + say qq[Output: ] . ($count + 0); +} diff --git a/challenge-341/peter-campbell-smith/perl/ch-2.pl b/challenge-341/peter-campbell-smith/perl/ch-2.pl new file mode 100755 index 0000000000..aad0f9b74e --- /dev/null +++ b/challenge-341/peter-campbell-smith/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge + +use v5.26; # The Weekly Challenge - 2025-09-29 +use utf8; # Week 341 - task 2 - Reverse prefix +use warnings; # Peter Campbell Smith +binmode STDOUT, ':utf8'; +use Encode; + +reverse_prefix('programming', 'g'); +reverse_prefix('hello', 'h'); +reverse_prefix('goodbye', 'e'); +reverse_prefix('noitulos', 's'); +reverse_prefix('conundrum', 'z'); + +sub reverse_prefix { + + my ($string, $char, $result); + + # initialise + ($string, $char) = @_; + + # do as instructed + if ($string =~ m|(.*?)$char(.*)|) { + $result = qq['$char] . reverse($1) . qq[$2']; + + # non-compliant data! + } else { + $result = qq[There is no '$char' in '$string']; + } + + say qq[\nInput: \$string = '$string', \$char = '$char']; + say qq[Output: $result]; +} |
