aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-22 23:49:43 +0100
committerGitHub <noreply@github.com>2025-09-22 23:49:43 +0100
commit5f2ddb536f7714e88eb8bfaf7bdeef60f2312bc7 (patch)
tree8b9115626e5532794edcc6a8869a2a66e8d8f2dd
parent8615bbb93f116e8044ef19be3ddebfe5d841b542 (diff)
parent6658443bcee36536b627e6bd2fb1ea71edb7126b (diff)
downloadperlweeklychallenge-club-5f2ddb536f7714e88eb8bfaf7bdeef60f2312bc7.tar.gz
perlweeklychallenge-club-5f2ddb536f7714e88eb8bfaf7bdeef60f2312bc7.tar.bz2
perlweeklychallenge-club-5f2ddb536f7714e88eb8bfaf7bdeef60f2312bc7.zip
Merge pull request #12719 from mahnkong/challenge-340
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");