From 64af807537f00aed047947952822da41577fd2ef Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 22 Sep 2025 10:00:31 +0200 Subject: Solve 340: Duplicate Removals && Ascending Numbers by E. Choroba --- challenge-340/e-choroba/perl/ch-1.pl | 20 ++++++++++++++++++++ challenge-340/e-choroba/perl/ch-2.pl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 challenge-340/e-choroba/perl/ch-1.pl create mode 100755 challenge-340/e-choroba/perl/ch-2.pl 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'; -- cgit