aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-280/kjetillll/perl/ch-1.pl11
-rw-r--r--challenge-280/kjetillll/perl/ch-2.pl11
2 files changed, 22 insertions, 0 deletions
diff --git a/challenge-280/kjetillll/perl/ch-1.pl b/challenge-280/kjetillll/perl/ch-1.pl
new file mode 100644
index 0000000000..368b4eca19
--- /dev/null
+++ b/challenge-280/kjetillll/perl/ch-1.pl
@@ -0,0 +1,11 @@
+use strict; use warnings; use Test::More tests=>3;
+
+sub first_twice {
+ my($str, %seen) = @_;
+ $str =~ s/^.// ? $seen{$&}++ ? $& : first_twice($str, %seen) : undef
+}
+
+is first_twice( $$_{input} ) => $$_{output}
+ for { input => "acbddbca", output => "d" },
+ { input => "abccd", output => "c" },
+ { input => "abcdabbb", output => "a" }
diff --git a/challenge-280/kjetillll/perl/ch-2.pl b/challenge-280/kjetillll/perl/ch-2.pl
new file mode 100644
index 0000000000..904a03eb3f
--- /dev/null
+++ b/challenge-280/kjetillll/perl/ch-2.pl
@@ -0,0 +1,11 @@
+use strict; use warnings; use Test::More tests=>3;
+
+sub count {
+ local $_ = shift;
+ s/ \| .*? \| //x ? count($_) : y/*//
+}
+
+is count( $$_{input} ) => $$_{output}
+ for { input => "p|*e*rl|w**e|*ekly|", output => 2 },
+ { input => "perl", output => 0 },
+ { input => "th|ewe|e**|k|l***ych|alleng|e", output => 5 }