aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-215/e-choroba/perl/ch-1.pl18
-rwxr-xr-xchallenge-215/e-choroba/perl/ch-2.pl16
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-215/e-choroba/perl/ch-1.pl b/challenge-215/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..6aaa049639
--- /dev/null
+++ b/challenge-215/e-choroba/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub odd_one_out(@words) {
+ scalar grep {
+ my $word = $_;
+ grep substr($word, $_ - 2, 1) gt substr($word, $_ - 1, 1),
+ 2 .. length $word
+ } @words
+}
+
+use Test::More tests => 3;
+
+is odd_one_out('abc', 'xyz', 'tsu'), 1, 'Example 1';
+is odd_one_out('rat', 'cab', 'dad'), 3, 'Example 2';
+is odd_one_out('x', 'y', 'z'), 0, 'Example 3';
diff --git a/challenge-215/e-choroba/perl/ch-2.pl b/challenge-215/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..3d90d73307
--- /dev/null
+++ b/challenge-215/e-choroba/perl/ch-2.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub number_placement($list, $count) {
+ (() = "@$list" =~ /0 0(?= 0)/g) >= $count ? 1 : 0
+}
+
+use Test::More tests => 3 + 1;
+is number_placement([1, 0, 0, 0, 1], 1), 1, 'Example 1';
+is number_placement([1, 0, 0, 0, 1], 2), 0, 'Example 2';
+is number_placement([1, 0, 0, 0, 0, 0, 0, 0, 1], 3), 1, 'Example 3';
+
+# Why /0(?= 0 0)/ is wrong:
+is number_placement([1, 0, 0, 0, 0, 0, 0, 1], 3), 0, 'Edge case';