diff options
| -rw-r--r-- | challenge-279/peter-campbell-smith/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-279/peter-campbell-smith/perl/ch-1.pl | 26 | ||||
| -rwxr-xr-x | challenge-279/peter-campbell-smith/perl/ch-2.pl | 28 |
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'); +} |
