aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Mahnke <andreas.mahnke@leuphana.de>2025-09-22 15:50:36 +0200
committerAndreas Mahnke <andreas.mahnke@leuphana.de>2025-09-22 15:51:10 +0200
commit6658443bcee36536b627e6bd2fb1ea71edb7126b (patch)
tree29c1a6afb0521947b4c1d8d0f89db2468a7d11d9
parentc4e70544812c339e0344ad3127de18a5dbf98c34 (diff)
downloadperlweeklychallenge-club-6658443bcee36536b627e6bd2fb1ea71edb7126b.tar.gz
perlweeklychallenge-club-6658443bcee36536b627e6bd2fb1ea71edb7126b.tar.bz2
perlweeklychallenge-club-6658443bcee36536b627e6bd2fb1ea71edb7126b.zip
Challenge 340
-rw-r--r--challenge-340/mahnkong/perl/ch-1.pl19
-rw-r--r--challenge-340/mahnkong/perl/ch-2.pl23
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-340/mahnkong/perl/ch-1.pl b/challenge-340/mahnkong/perl/ch-1.pl
new file mode 100644
index 0000000000..73832ce163
--- /dev/null
+++ b/challenge-340/mahnkong/perl/ch-1.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($string) {
+ my $old;
+ do {
+ $old = $string;
+ $string =~ s/([A-Za-z])\1//g;
+ } while ($old ne $string);
+ return $string;
+}
+
+is(run("abbaca"), "ca", "Example 1");
+is(run("azxxzy"), "ay", "Example 2");
+is(run("aaaaaaaa"), "", "Example 3");
+is(run("aabccba"), "a", "Example 4");
+is(run("abcddcba"), "", "Example 5");
diff --git a/challenge-340/mahnkong/perl/ch-2.pl b/challenge-340/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..d7ea445e35
--- /dev/null
+++ b/challenge-340/mahnkong/perl/ch-2.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($string) {
+ my $last;
+ while ($string =~ /(\d+)/g) {
+ if (defined $last && $last >= $1) {
+ return 0;
+ }
+ $last = $1;
+ }
+ defined $last ? 1 : 0;
+}
+
+is(run("The cat has 3 kittens 7 toys 10 beds"), 1, "Example 1");
+is(run("Alice bought 5 apples 2 oranges 9 bananas"), 0, "Example 2");
+is(run("I ran 1 mile 2 days 3 weeks 4 months"), 1, "Example 3");
+is(run("Bob has 10 cars 10 bikes"), 0, "Example 4");
+is(run("Zero is 0 one is 1 two is 2"), 1, "Example 5");
+is(run("Keine einzige Nummer"), 0, "Example 6");
+is(run("Nur 1 Nummer"), 1, "Example 7");