aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Campbell Smith <pj.campbell.smith@gmail.com>2023-05-01 14:18:48 +0100
committerPeter Campbell Smith <pj.campbell.smith@gmail.com>2023-05-01 14:18:48 +0100
commit8b8f9a276446f9a6cf710bedbbaa16f4da36b65b (patch)
tree66101694be305fafac44cd23f4d8051594c14f71
parent6cc2e38f43011f65d7deaf1e03cf55e4306a53e5 (diff)
downloadperlweeklychallenge-club-8b8f9a276446f9a6cf710bedbbaa16f4da36b65b.tar.gz
perlweeklychallenge-club-8b8f9a276446f9a6cf710bedbbaa16f4da36b65b.tar.bz2
perlweeklychallenge-club-8b8f9a276446f9a6cf710bedbbaa16f4da36b65b.zip
Week 215 submissions
-rw-r--r--challenge-215/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-215/peter-campbell-smith/perl/ch-1.pl25
-rwxr-xr-xchallenge-215/peter-campbell-smith/perl/ch-2.pl28
3 files changed, 54 insertions, 0 deletions
diff --git a/challenge-215/peter-campbell-smith/blog.txt b/challenge-215/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..7cdb832f79
--- /dev/null
+++ b/challenge-215/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+http://ccgi.campbellsmiths.force9.co.uk/challenge/215
diff --git a/challenge-215/peter-campbell-smith/perl/ch-1.pl b/challenge-215/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..605d8dd561
--- /dev/null
+++ b/challenge-215/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use v5.16; # The Weekly Challenge - 2023-05-01
+use utf8; # Week 215 task 1 - Odd one out
+use strict; # Peter Campbell Smith
+use warnings; # Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+odd_one_out('abc', 'xyz', 'tsu');
+odd_one_out('rat', 'cab', 'dad');
+odd_one_out('x', 'y', 'z');
+odd_one_out('hippy', 'afoot', 'in', 'chilly', 'abbey');
+odd_one_out('write', 'a', 'script', 'to', 'remove', 'all', 'words', 'not', 'sorted', 'alphabetically');
+odd_one_out('abc', 'aBc', 'abC', 'bcA');
+
+sub odd_one_out {
+
+ my ($word, $count);
+
+ $count = 0;
+ for $word (@_) {
+ $count ++ if lc($word) ne join('', sort split('', lc($word)));
+ }
+ say qq[\nInput: \@words = ('] . join(q[', '], @_) . q[')];
+ say qq[Output: $count];
+} \ No newline at end of file
diff --git a/challenge-215/peter-campbell-smith/perl/ch-2.pl b/challenge-215/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..149cba84e7
--- /dev/null
+++ b/challenge-215/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use v5.16; # The Weekly Challenge - 2023-05-01
+use utf8; # Week 215 task 2 - Number placement
+use strict; # Peter Campbell Smith
+use warnings; # Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge
+
+number_placement([1, 0, 0, 0, 1], 1);
+number_placement([1, 0, 0, 0, 1], 2);
+number_placement([0, 0, 1, 0, 0, 0, 1, 0, 0], 3);
+
+sub number_placement {
+
+ my (@numbers, $count, $string, $j, $done);
+
+ @numbers = @{$_[0]};
+ $count = $_[1];
+
+ $string = join('', @numbers);
+ for $j (1 .. $count) {
+ $done ++ if ($string =~ s|000|010| or
+ $string =~ s|^00|10| or $string =~ s|00$|01|);
+ }
+ say qq[\nInput: \@numbers = (] . join(', ', @numbers) .
+ qq[), \$count = $count];
+ say qq[Output: ] . ($done == $count ? 1 : 0);
+
+} \ No newline at end of file