diff options
| -rw-r--r-- | challenge-340/mahnkong/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-340/mahnkong/perl/ch-2.pl | 23 |
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"); |
