aboutsummaryrefslogtreecommitdiff
path: root/challenge-340
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-340')
-rwxr-xr-xchallenge-340/torgny-lyon/perl/ch-1.pl17
-rwxr-xr-xchallenge-340/torgny-lyon/perl/ch-2.pl18
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-340/torgny-lyon/perl/ch-1.pl b/challenge-340/torgny-lyon/perl/ch-1.pl
new file mode 100755
index 0000000000..d60a6000b8
--- /dev/null
+++ b/challenge-340/torgny-lyon/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use v5.42;
+
+use Test::More tests => 5;
+
+sub remove_duplicates {
+ my $s = shift;
+ while ($s =~ s/(.)\1//g) {}
+ $s;
+}
+
+is(remove_duplicates('abbaca'), 'ca');
+is(remove_duplicates('azxxzy'), 'ay');
+is(remove_duplicates('aaaaaaaa'), q{});
+is(remove_duplicates('aabccba'), 'a');
+is(remove_duplicates('abcddcba'), q{});
diff --git a/challenge-340/torgny-lyon/perl/ch-2.pl b/challenge-340/torgny-lyon/perl/ch-2.pl
new file mode 100755
index 0000000000..7f5484bd84
--- /dev/null
+++ b/challenge-340/torgny-lyon/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use v5.42;
+
+use Test::More tests => 5;
+
+use List::Util qw(all);
+
+sub is_ascending {
+ my @numbers = $_[0] =~ /\d+/g;
+ all { $numbers[$_] < $numbers[$_ + 1] } 0..($#numbers -1);
+}
+
+ok( is_ascending('The cat has 3 kittens 7 toys 10 beds'));
+ok(not is_ascending('Alice bought 5 apples 2 oranges 9 bananas'));
+ok( is_ascending('I ran 1 mile 2 days 3 weeks 4 months'));
+ok(not is_ascending('Bob has 10 cars 10 bikes'));
+ok( is_ascending('Zero is 0 one is 1 two is 2'));