aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-280/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-280/peter-campbell-smith/perl/ch-1.pl32
-rwxr-xr-xchallenge-280/peter-campbell-smith/perl/ch-2.pl29
3 files changed, 62 insertions, 0 deletions
diff --git a/challenge-280/peter-campbell-smith/blog.txt b/challenge-280/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..a2a7a7403b
--- /dev/null
+++ b/challenge-280/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/challenge/280
diff --git a/challenge-280/peter-campbell-smith/perl/ch-1.pl b/challenge-280/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..97ac70bf73
--- /dev/null
+++ b/challenge-280/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-07-29
+use utf8; # Week 280 - task 1 - Twice appearance
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+twice_appearance('acbddbca');
+twice_appearance('abccd');
+twice_appearance('abcdabbb');
+twice_appearance('aabcdef');
+twice_appearance('abcdeff');
+twice_appearance('soporific');
+
+sub twice_appearance {
+
+ my ($str, $j, $a);
+ $str = shift;
+
+ # iterate along string
+ for $j (0 .. length($str) - 1) {
+ $a = substr($str, $j, 1);
+
+ # check if this letter appears twice
+ last if $str =~ m|$a.*$a|;
+ $a = '';
+ }
+ printf(qq[\nInput: \@str = '%s'\n], $str);
+ printf(qq[Output: '%s'\n], $a);
+}
diff --git a/challenge-280/peter-campbell-smith/perl/ch-2.pl b/challenge-280/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..d7ec13c6b3
--- /dev/null
+++ b/challenge-280/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-07-29
+use utf8; # Week 280 - task 2 - Count asterisks
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+count_asterisks('p|*e*rl|w**e|*ekly|');
+count_asterisks('perl');
+count_asterisks('th|ewe|e**|k|l***ych|alleng|e');
+count_asterisks('*****|*****|*****|*****|');
+
+sub count_asterisks {
+
+ my ($str);
+
+ $str = shift @_;
+ printf(qq[\nInput: \@str = '%s'\n], $str);
+
+ # remove |.*?| from $str
+ $str =~ s/\|.*?\|//g;
+
+ # remove non * from $str
+ $str =~ s|[^\*]||g;
+
+ printf(qq[Output: %s\n], length($str));
+}