diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-09-22 23:46:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-22 23:46:30 +0100 |
| commit | 4ca446479121cde9e984850dd2a6539e141d13ef (patch) | |
| tree | 18f360edde173c355b3f09256a1cbe3cc625007f | |
| parent | f7735f052505c50b29ee93599feafe6b999117ab (diff) | |
| parent | 64af807537f00aed047947952822da41577fd2ef (diff) | |
| download | perlweeklychallenge-club-4ca446479121cde9e984850dd2a6539e141d13ef.tar.gz perlweeklychallenge-club-4ca446479121cde9e984850dd2a6539e141d13ef.tar.bz2 perlweeklychallenge-club-4ca446479121cde9e984850dd2a6539e141d13ef.zip | |
Merge pull request #12715 from choroba/ech340
Solve 340: Duplicate Removals && Ascending Numbers by E. Choroba
| -rwxr-xr-x | challenge-340/e-choroba/perl/ch-1.pl | 20 | ||||
| -rwxr-xr-x | challenge-340/e-choroba/perl/ch-2.pl | 34 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-340/e-choroba/perl/ch-1.pl b/challenge-340/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..7704ac07aa --- /dev/null +++ b/challenge-340/e-choroba/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub duplicate_removals($str) { + 1 while $str =~ s/(.)\1//g; + return $str +} + +use Test::More tests => 5 + 2; + +is duplicate_removals('abbaca'), 'ca', 'Example 1'; +is duplicate_removals('azxxzy'), 'ay', 'Example 2'; +is duplicate_removals('aaaaaaaa'), "", 'Example 3'; +is duplicate_removals('aabccba'), 'a', 'Example 4'; +is duplicate_removals('abcddcba'), "", 'Example 5'; + +is duplicate_removals('aaa'), 'a', 'Odd length'; +is duplicate_removals('aabccdeedffbgg'), "", 'Many steps'; diff --git a/challenge-340/e-choroba/perl/ch-2.pl b/challenge-340/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..8df9da1ad3 --- /dev/null +++ b/challenge-340/e-choroba/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub ascending_numbers($str) { + my @numbers = $str =~ /(\d+)/ag; + for my $i (1 .. $#numbers) { + return if $numbers[$i] <= $numbers[ $i - 1 ]; + } + return 1 +} + +use constant { true => !0, false => !1 }; +use Test2::V0; +plan(5 + 1); + +is ascending_numbers('The cat has 3 kittens 7 toys 10 beds'), + bool(true), + 'Example 1'; +is ascending_numbers('Alice bought 5 apples 2 oranges 9 bananas'), + bool(false), + 'Example 2'; +is ascending_numbers('I ran 1 mile 2 days 3 weeks 4 months'), + bool(true), + 'Example 3'; +is ascending_numbers('Bob has 10 cars 10 bikes'), + bool(false), + 'Example 4'; +is ascending_numbers('Zero is 0 one is 1 two is 2'), + bool(true), + 'Example 5'; + +is ascending_numbers('There are no numbers'), bool(true), 'No numbers'; |
