aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwanderdoc <wanderdoc@users.noreply.github.com>2025-07-15 14:02:26 +0200
committerGitHub <noreply@github.com>2025-07-15 14:02:26 +0200
commitb16659a7afb35fa8f0359d98c8f4db7b0a66951f (patch)
treefa11f5b5a474732c743b71b46ba1af250185d702
parent5cccfc981512e14a5bcee9964ff8391f2e4da93b (diff)
downloadperlweeklychallenge-club-b16659a7afb35fa8f0359d98c8f4db7b0a66951f.tar.gz
perlweeklychallenge-club-b16659a7afb35fa8f0359d98c8f4db7b0a66951f.tar.bz2
perlweeklychallenge-club-b16659a7afb35fa8f0359d98c8f4db7b0a66951f.zip
Create ch-1.pl
-rw-r--r--challenge-330/wanderdoc/perl/ch-1.pl49
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-330/wanderdoc/perl/ch-1.pl b/challenge-330/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..fb8759376c
--- /dev/null
+++ b/challenge-330/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,49 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given a string containing only lower case English letters and digits.
+Write a script to remove all digits by removing the first digit and the closest non-digit character to its left.
+
+Example 1
+
+Input: $str = "cab12"
+Output: "c"
+
+Round 1: remove "1" then "b" => "ca2"
+Round 2: remove "2" then "a" => "c"
+
+
+Example 2
+
+Input: $str = "xy99"
+Output: ""
+
+Round 1: remove "9" then "y" => "x9"
+Round 2: remove "9" then "x" => ""
+
+
+Example 3
+
+Input: $str = "pa1erl"
+Output: "perl"
+=cut
+
+use Test2::V0 -no_srand => 1;
+is(clear_digits("cab12"), "c", "Example 1");
+is(clear_digits("xy99"), "", "Example 2");
+is(clear_digits("pa1erl"), "perl", "Example 3");
+done_testing();
+
+
+
+sub clear_digits
+{
+ my $str = $_[0];
+ while ( $str =~ /\d/ )
+ {
+ $str =~ s/([a-z]\d)//;
+ }
+ return $str;
+}