aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-308/e-choroba/perl/ch-1.pl23
-rwxr-xr-xchallenge-308/e-choroba/perl/ch-2.pl20
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-308/e-choroba/perl/ch-1.pl b/challenge-308/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..7898f7ed07
--- /dev/null
+++ b/challenge-308/e-choroba/perl/ch-1.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub count_common($str1, $str2) {
+ my %common;
+ @common{ @$str1 } = (1) x @$str1;
+ $common{$_} |= 2 for @$str2;
+ return scalar grep $_ == 3, values %common
+}
+
+use Test::More tests => 3;
+
+is count_common(['perl', 'weekly', 'challenge'],
+ ['raku', 'weekly', 'challenge']),
+ 2, 'Example 1';
+
+is count_common(['perl', 'raku', 'python'], ['python', 'java']),
+ 1, 'Example 2';
+
+is count_common(['guest', 'contribution'], ['fun', 'weekly', 'challenge']),
+ 0, 'Example 3';
diff --git a/challenge-308/e-choroba/perl/ch-2.pl b/challenge-308/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..9b09d5c2ba
--- /dev/null
+++ b/challenge-308/e-choroba/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub decode_xor($initial, @encoded) {
+ my @decoded;
+ for my $i ($initial, @encoded) {
+ push @decoded, $i ^ ($decoded[-1] // 0);
+ }
+ return \@decoded
+}
+
+use Test2::V0;
+plan(2 + 1);
+
+is decode_xor(1, 1, 2, 3), [1, 0, 2, 1], 'Example 1';
+is decode_xor(4, 6, 2, 7, 3), [4, 2, 0, 7, 4], 'Example 2';
+
+is decode_xor(1, 1, 2, 5), [1, 0, 2, 7], 'Initial different to last';