aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetilS <kjetilskotheim@gmail.com>2024-07-31 00:52:59 +0200
committerKjetilS <kjetilskotheim@gmail.com>2024-07-31 00:52:59 +0200
commitb44bb59605eb468f6f1fe6ebc4298aad28177dfe (patch)
tree03235f57aa4674de45c807463ee9d004890169b4
parent027b1391cba3d6522b43f784a6f36b79f106100b (diff)
downloadperlweeklychallenge-club-b44bb59605eb468f6f1fe6ebc4298aad28177dfe.tar.gz
perlweeklychallenge-club-b44bb59605eb468f6f1fe6ebc4298aad28177dfe.tar.bz2
perlweeklychallenge-club-b44bb59605eb468f6f1fe6ebc4298aad28177dfe.zip
https://theweeklychallenge.org/blog/perl-weekly-challenge-280/
-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 }