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