aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-08-12 12:54:42 +0100
committerGitHub <noreply@github.com>2024-08-12 12:54:42 +0100
commit4771968984773fb843ab514749590161db3e59d8 (patch)
tree0f9a2ffa04ae8c0973d137fd3d770ccb0be8b054
parent06d85752a276e45b5d4fa48366da43d17a244210 (diff)
parentc505ae57f3cb10f6c84dd9bd373dbe456d3031eb (diff)
downloadperlweeklychallenge-club-4771968984773fb843ab514749590161db3e59d8.tar.gz
perlweeklychallenge-club-4771968984773fb843ab514749590161db3e59d8.tar.bz2
perlweeklychallenge-club-4771968984773fb843ab514749590161db3e59d8.zip
Merge pull request #10593 from pjcs00/wk282
Week 282 - Integggers and keys
-rw-r--r--challenge-282/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-282/peter-campbell-smith/perl/ch-1.pl39
-rwxr-xr-xchallenge-282/peter-campbell-smith/perl/ch-2.pl32
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-282/peter-campbell-smith/blog.txt b/challenge-282/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..d05f459565
--- /dev/null
+++ b/challenge-282/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/challenge/281
diff --git a/challenge-282/peter-campbell-smith/perl/ch-1.pl b/challenge-282/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..ddfe6d6b37
--- /dev/null
+++ b/challenge-282/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-08-12
+use utf8; # Week 282 - task 1 - Good integer
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+# good ones
+good_integer('12333456');
+good_integer('333456');
+good_integer('456333');
+good_integer('129934956799998999');
+
+# bad ones
+good_integer('123333456');
+good_integer('3333456');
+good_integer('123333');
+good_integer('123345');
+
+sub good_integer {
+
+ my $int = $_[0];
+ say qq[\nInput: \$int = $int];
+
+ # pad left and right with non-integer
+ $int = qq[¦$int¦];
+
+ # check for xyyyz pattern
+ while ($int =~ m|(.)(.)\2\2(.)|g) {
+ next unless ($1 ne $2 and $2 ne $3);
+
+ # pattern found!
+ say qq[Output: $2$2$2];
+ return;
+ }
+ say qq[Output: -1];
+}
diff --git a/challenge-282/peter-campbell-smith/perl/ch-2.pl b/challenge-282/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..e1878302da
--- /dev/null
+++ b/challenge-282/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+use v5.26; # The Weekly Challenge - 2024-08-12
+use utf8; # Week 282 - task 2 - Changing keys
+use warnings; # Peter Campbell Smith
+binmode STDOUT, ':utf8';
+
+changing_keys('aaabbbcCc');
+changing_keys('abbbbb');
+changing_keys('aaaaab');
+changing_keys('abcde');
+changing_keys('aAaAaAa');
+changing_keys('Committee');
+
+sub changing_keys {
+
+ my ($str, $c, $count);
+
+ # initialise
+ $str = shift;
+ say qq[\nInput: \@str = '$str'];
+
+ # count key changes
+ $str = lc($str);
+ $count = 0;
+ for $c (0 .. length($str) - 2) {
+ $count ++ if substr($str, $c, 1) ne substr($str, $c + 1, 1);
+ }
+ say qq[Output: $count];
+}