aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-22 13:54:16 +0100
committerGitHub <noreply@github.com>2024-07-22 13:54:16 +0100
commite01a13ec4ca60c8454c9e13855711dfe2a799cd0 (patch)
treef1e88777687950714f84d9ee816f0e7e94c19dc6
parent274bf4a39a2a89b95ebbc89cea4d775f2c8eaead (diff)
parent0330d801e12e7af755e1877eba6b42d1174c0230 (diff)
downloadperlweeklychallenge-club-e01a13ec4ca60c8454c9e13855711dfe2a799cd0.tar.gz
perlweeklychallenge-club-e01a13ec4ca60c8454c9e13855711dfe2a799cd0.tar.bz2
perlweeklychallenge-club-e01a13ec4ca60c8454c9e13855711dfe2a799cd0.zip
Merge pull request #10477 from pjcs00/wk279
Week 279 - Scrambled and split
-rw-r--r--challenge-279/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-279/peter-campbell-smith/perl/ch-1.pl26
-rwxr-xr-xchallenge-279/peter-campbell-smith/perl/ch-2.pl28
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-279/peter-campbell-smith/blog.txt b/challenge-279/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..f13a0f3290
--- /dev/null
+++ b/challenge-279/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/pwc/challenge/279
diff --git a/challenge-279/peter-campbell-smith/perl/ch-1.pl b/challenge-279/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..29037c68eb
--- /dev/null
+++ b/challenge-279/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-07-22
+use utf8; # Week 279 - task 1 - Sort letters
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+sort_letters(['R', 'E', 'P', 'L'], [3, 2, 1, 4]);
+sort_letters(['A', 'U', 'R', 'K'], [2, 4, 1, 3]);
+sort_letters(['a', 'C', 'e', 'e', 'g', 'h', 'l', 'l', 'n'], [3, 1, 6, 9, 8, 2, 4, 5, 7]);
+
+sub sort_letters {
+
+ my (@letters, @weights, @sorted);
+
+ @letters = @{$_[0]};
+ @weights = @{$_[1]};
+
+ # rearrange the letters
+ $sorted[$weights[$_] - 1] = $letters[$_] for 0 .. @letters - 1;
+
+ printf(qq[\nInput: \@letters = ('%s'), \@weights = (%s)\n], join(qq[', '], @letters), join(', ', @weights));
+ printf(qq[Output: %s\n], join('', @sorted));
+}
diff --git a/challenge-279/peter-campbell-smith/perl/ch-2.pl b/challenge-279/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..fee176507d
--- /dev/null
+++ b/challenge-279/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-07-22
+use utf8; # Week 279 - task 2 - Split string
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+split_string('good morning');
+split_string('perl');
+split_string('Write a script to split the given string into two');
+split_string('Write a script to split the given string into three');
+split_string('bcdfgh');
+split_string('');
+
+sub split_string {
+
+ my ($string, $vowels);
+
+ $string = shift;
+
+ # count the vowels
+ $vowels = () = $string =~ m|[aeiou]|gi;
+
+ printf(qq[\nInput: \$str = '%s'\n], $string);
+ printf(qq[Output: %s\n], ($vowels & 1) ? 'false' : 'true');
+}