diff options
| author | Torgny Lyon <torgny@abc.se> | 2025-09-28 15:54:37 +0200 |
|---|---|---|
| committer | Torgny Lyon <torgny@abc.se> | 2025-09-28 15:55:19 +0200 |
| commit | daeca2d136943afbe75f072c316eaefab4aa8ee9 (patch) | |
| tree | 7b2f83755e3744ee7e2dd6f8353428a1bf9daa4e | |
| parent | 7475a6136d1eb9d82919dbc9d53e5e246918cd20 (diff) | |
| download | perlweeklychallenge-club-daeca2d136943afbe75f072c316eaefab4aa8ee9.tar.gz perlweeklychallenge-club-daeca2d136943afbe75f072c316eaefab4aa8ee9.tar.bz2 perlweeklychallenge-club-daeca2d136943afbe75f072c316eaefab4aa8ee9.zip | |
Add solutions for week 340
| -rwxr-xr-x | challenge-340/torgny-lyon/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-340/torgny-lyon/perl/ch-2.pl | 18 |
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')); |
