aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-11 12:54:20 +0100
committerGitHub <noreply@github.com>2024-06-11 12:54:20 +0100
commit2eace0f9656e6e88ddc9418cc39adb9f57fc5cc1 (patch)
tree001072120bb70626d36f02d571411131ae33a25f
parent4aec4c9ba5afcfdd64e089272280667dfa356caa (diff)
parentfad50cc7b38a6b9d1a86f8b4b6886d611f34610b (diff)
downloadperlweeklychallenge-club-2eace0f9656e6e88ddc9418cc39adb9f57fc5cc1.tar.gz
perlweeklychallenge-club-2eace0f9656e6e88ddc9418cc39adb9f57fc5cc1.tar.bz2
perlweeklychallenge-club-2eace0f9656e6e88ddc9418cc39adb9f57fc5cc1.zip
Merge pull request #10242 from pjcs00/wk273
Week 273 - All about characters
-rw-r--r--challenge-273/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-273/peter-campbell-smith/perl/ch-1.pl26
-rwxr-xr-xchallenge-273/peter-campbell-smith/perl/ch-2.pl24
3 files changed, 51 insertions, 0 deletions
diff --git a/challenge-273/peter-campbell-smith/blog.txt b/challenge-273/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..51209c8de0
--- /dev/null
+++ b/challenge-273/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/challenge/273
diff --git a/challenge-273/peter-campbell-smith/perl/ch-1.pl b/challenge-273/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..5c83632497
--- /dev/null
+++ b/challenge-273/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-06-10
+use utf8; # Week 273 - task 1 - Percentage of character
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+percentage_of_character('the cat sat on the mat', 'a');
+percentage_of_character('percentage of character', 'g');
+percentage_of_character('the weekly challenge', 'z');
+percentage_of_character('zzzzzzzzzzzzzzzzzz', 'z');
+
+sub percentage_of_character {
+
+ my ($str, $char, $chars);
+
+ # remove $char from $str
+ ($str, $char) = @_;
+ $chars = $str;
+ $chars =~ s|[^$char]+||g;
+
+ say qq[\nInput: \$str = '$str', \$char = '$char'];
+ say qq[Output: ] . int(length($chars) / length($str) * 100 + 0.5);
+}
diff --git a/challenge-273/peter-campbell-smith/perl/ch-2.pl b/challenge-273/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..9e4b5701f8
--- /dev/null
+++ b/challenge-273/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-06-10
+use utf8; # Week 273 - task 2 - B after a
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+b_after_a('aabb');
+b_after_a('abab');
+b_after_a('aaa');
+b_after_a('bbb');
+b_after_a('ccc');
+b_after_a('Write a script to return true if there is at least one b');
+
+sub b_after_a {
+
+ my $str = $_[0];
+
+ # match a 'b', and then match no 'a' in the rest of the string
+ say qq[\nInput: \$str = '$str'];
+ say qq[Output: ] . (($str =~ m|b(.*)| and $1 =~ m|^[^a]*$|) ? 'true' : 'false');
+}