aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-14 11:35:24 +0100
committerGitHub <noreply@github.com>2024-04-14 11:35:24 +0100
commit2e7a3008d30320520aff3ebfa94c992ed0a29bad (patch)
tree6d60b82e359347dcb13097c134428d5579a22a1b
parentb17f00846e519dfde6f39248305b0dc5998c6c34 (diff)
parent4fa050a9ab0aba28986c44ea13c56db00b602b9a (diff)
downloadperlweeklychallenge-club-2e7a3008d30320520aff3ebfa94c992ed0a29bad.tar.gz
perlweeklychallenge-club-2e7a3008d30320520aff3ebfa94c992ed0a29bad.tar.bz2
perlweeklychallenge-club-2e7a3008d30320520aff3ebfa94c992ed0a29bad.zip
Merge pull request #9918 from pjcs00/wk264
Week 264 - a bit late ...
-rw-r--r--challenge-264/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-264/peter-campbell-smith/perl/ch-1.pl37
-rwxr-xr-xchallenge-264/peter-campbell-smith/perl/ch-2.pl48
3 files changed, 86 insertions, 0 deletions
diff --git a/challenge-264/peter-campbell-smith/blog.txt b/challenge-264/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..f2e72672d8
--- /dev/null
+++ b/challenge-264/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/challenge/264
diff --git a/challenge-264/peter-campbell-smith/perl/ch-1.pl b/challenge-264/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..a1860f14b6
--- /dev/null
+++ b/challenge-264/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-04-08
+use utf8; # Week 264 - task 1 - Greatest English letter
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+greatest_english_letter('PeRlwEeKLy');
+greatest_english_letter('zebras live in London Zoo');
+greatest_english_letter('Antelopes like chocolate');
+greatest_english_letter('all lower case gives a null result');
+greatest_english_letter('the lower case can come fiRst');
+greatest_english_letter('maybe harder - yAaBbcCdDY');
+
+sub greatest_english_letter {
+
+ my ($str, $C, $c, $m);
+
+ $str = shift;
+ say qq[\nInput: \$str = '$str'];
+
+ # reverse sort characters of $str
+ $str = join('', sort { $b cmp $a } split('', $str));
+
+ # loop over lc chars in $str
+ while ($str =~ m|([a-z])|g) {
+ $C = uc($1);
+
+ # test for uc same char
+ next unless $str =~ m|$1.*$C|;
+ say qq[Output: '$C'];
+ return;
+ }
+ say qq[Output: ''];
+}
diff --git a/challenge-264/peter-campbell-smith/perl/ch-2.pl b/challenge-264/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..9503d8b471
--- /dev/null
+++ b/challenge-264/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-04-08
+use utf8; # Week 264 - task 2 - Target array
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+target_array([0, 1, 2, 3, 4], [0, 1, 2, 2, 1]);
+target_array([1, 2, 3, 4, 0], [0, 1, 2, 3, 0]);
+target_array([1], [0]);
+target_array([0, 1, 2, 3, 4], [3, 0, 4, 3, 2]);
+target_array([11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [9, 4, 2, 7, 5, 8, 1, 0, 3, 6]);
+target_array([11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+sub target_array {
+
+ my (@source, @indices, @target, $i, $j, $k, $hold, $value);
+
+ @source = @{$_[0]};
+ @indices = @{$_[1]};
+
+ # loop over indices
+ for $i (0 .. @indices - 1) {
+ $j = $indices[$i];
+ $value = $target[$j];
+
+ # if the place in @target is occupied, move it and subsequent ones right
+ $k = $j;
+ while (defined $value) {
+ $hold = $target[$k];
+ $target[$k] = $value;
+ $value = $hold;
+ $k ++;
+ }
+ $target[$j] = $source[$i];
+ }
+
+ # show results (with '?' for undefined - see analysis)
+ for ($j = 0; $j < @target; $j ++) {
+ $target[$j] = '?' unless defined $target[$j];
+ }
+
+ say qq[\nInput: \@source = (] . join(', ', @source) . ')';
+ say qq[ \@indices = (] . join(', ', @indices) . ')';
+ say qq[Output: (] . join(', ', @target) . ')';
+}