aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-07-15 11:01:05 +0100
committerGitHub <noreply@github.com>2025-07-15 11:01:05 +0100
commitb5a6c9ff273686dcafc81f2016fe0a9bb206ecba (patch)
tree18c2d637b57de0f851a4e7b00a9a9c754813813b
parentf0f9cb0868604d1802c73fa4963fb01c80a41ec2 (diff)
parent0f6ac5d45af66049d10aef2f9db6e59cbdc94749 (diff)
downloadperlweeklychallenge-club-b5a6c9ff273686dcafc81f2016fe0a9bb206ecba.tar.gz
perlweeklychallenge-club-b5a6c9ff273686dcafc81f2016fe0a9bb206ecba.tar.bz2
perlweeklychallenge-club-b5a6c9ff273686dcafc81f2016fe0a9bb206ecba.zip
Merge pull request #12352 from jeanluc2020/jeanluc2020-330
Add solution 330.
-rw-r--r--challenge-330/jeanluc2020/blog-1.txt1
-rw-r--r--challenge-330/jeanluc2020/blog-2.txt1
-rwxr-xr-xchallenge-330/jeanluc2020/perl/ch-1.pl58
-rwxr-xr-xchallenge-330/jeanluc2020/perl/ch-2.pl60
4 files changed, 120 insertions, 0 deletions
diff --git a/challenge-330/jeanluc2020/blog-1.txt b/challenge-330/jeanluc2020/blog-1.txt
new file mode 100644
index 0000000000..146407b5b3
--- /dev/null
+++ b/challenge-330/jeanluc2020/blog-1.txt
@@ -0,0 +1 @@
+http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-330-1.html
diff --git a/challenge-330/jeanluc2020/blog-2.txt b/challenge-330/jeanluc2020/blog-2.txt
new file mode 100644
index 0000000000..f647216e7f
--- /dev/null
+++ b/challenge-330/jeanluc2020/blog-2.txt
@@ -0,0 +1 @@
+http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-330-2.html
diff --git a/challenge-330/jeanluc2020/perl/ch-1.pl b/challenge-330/jeanluc2020/perl/ch-1.pl
new file mode 100755
index 0000000000..0bf8baae23
--- /dev/null
+++ b/challenge-330/jeanluc2020/perl/ch-1.pl
@@ -0,0 +1,58 @@
+#!/usr/bin/env perl
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-330/#TASK1
+#
+# Task 1: Clear Digits
+# ====================
+#
+# 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"
+#
+############################################################
+##
+## discussion
+##
+############################################################
+#
+# Long description short, as long as there is still a non-digit
+# before a digit, remove those two characters.
+# Note: If the string starts with a digit, but then has other characters before
+# other digits, this will still remove the later digit. It's not 100% clear
+# whether this is an allowed input though.
+
+use v5.36;
+
+clear_digits("cab12");
+clear_digits("xy99");
+clear_digits("pa1erl");
+
+sub clear_digits($str) {
+ say "Input: \"$str\"";
+ while($str =~ s/[^\d]\d//) {
+ }
+ say "Output: \"$str\"";
+}
diff --git a/challenge-330/jeanluc2020/perl/ch-2.pl b/challenge-330/jeanluc2020/perl/ch-2.pl
new file mode 100755
index 0000000000..c84348ce58
--- /dev/null
+++ b/challenge-330/jeanluc2020/perl/ch-2.pl
@@ -0,0 +1,60 @@
+#!/usr/bin/env perl
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-330/#TASK2
+#
+# Task 2: Title Capital
+# =====================
+#
+# You are given a string made up of one or more words separated by a single
+# space.
+#
+# Write a script to capitalise the given title. If the word length is 1 or 2
+# then convert the word to lowercase otherwise make the first character
+# uppercase and remaining lowercase.
+#
+## Example 1
+##
+## Input: $str = "PERL IS gREAT"
+## Output: "Perl is Great"
+#
+#
+## Example 2
+##
+## Input: $str = "THE weekly challenge"
+## Output: "The Weekly Challenge"
+#
+#
+## Example 3
+##
+## Input: $str = "YoU ARE A stAR"
+## Output: "You Are a Star"
+#
+############################################################
+##
+## discussion
+##
+############################################################
+#
+# We split the input into the individual words. Then we lowercase all words of
+# a length <= 2. For the words longer than that, we uppercase the first
+# character and lowercase the rest. In the end, we join the words together
+# again to form the full sentence.
+
+use v5.36;
+
+title_capital("PERL IS gREAT");
+title_capital("THE weekly challenge");
+title_capital("YoU ARE A stAR");
+
+sub title_capital($str) {
+ say "Input: \"$str\"";
+ my @output = ();
+ my @words = split /\s+/, $str;
+ foreach my $word (@words) {
+ if(length($word) <= 2) {
+ push @output, lc($word);
+ } else {
+ push @output, uc(substr($word,0,1)) . lc(substr($word,1));
+ }
+ }
+ say "Output: " . join(" ", @output);
+}