aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2025-07-21 08:15:29 -0600
committerLuis Mochan <mochan@fis.unam.mx>2025-07-21 08:15:29 -0600
commita8609bdf63cf6d5f0780c676b5cf4d48ecd72cbb (patch)
treea553d4da0568bc058806f9dde8d8d67cf39237ea
parente0f7e800fc8f1b2cb50896852a0a3ed61980f510 (diff)
downloadperlweeklychallenge-club-a8609bdf63cf6d5f0780c676b5cf4d48ecd72cbb.tar.gz
perlweeklychallenge-club-a8609bdf63cf6d5f0780c676b5cf4d48ecd72cbb.tar.bz2
perlweeklychallenge-club-a8609bdf63cf6d5f0780c676b5cf4d48ecd72cbb.zip
Solve PWC331
-rw-r--r--challenge-331/wlmb/blog.txt1
-rwxr-xr-xchallenge-331/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-331/wlmb/perl/ch-2.pl27
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-331/wlmb/blog.txt b/challenge-331/wlmb/blog.txt
new file mode 100644
index 0000000000..837eeaee1c
--- /dev/null
+++ b/challenge-331/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2025/07/21/PWC331/
diff --git a/challenge-331/wlmb/perl/ch-1.pl b/challenge-331/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..f49164cec9
--- /dev/null
+++ b/challenge-331/wlmb/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 331
+# Task 1: Last Word
+#
+# See https://wlmb.github.io/2025/07/21/PWC331/#task-1-last-word
+use v5.36;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 S1 S2...
+ to find the length of the last word of the strings Sn
+ FIN
+for(@ARGV){
+ say "$_ -> ", # print the result
+ length # compute the length
+ [split " "] # separate into words
+ ->[-1] # choose last word
+ =~s/\W//gr # remove non-word characters
+}
diff --git a/challenge-331/wlmb/perl/ch-2.pl b/challenge-331/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..51f3e6f145
--- /dev/null
+++ b/challenge-331/wlmb/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 331
+# Task 2: Buddy Strings
+#
+# See https://wlmb.github.io/2025/07/21/PWC331/#task-2-buddy-strings
+use v5.36;
+die <<~"FIN" unless @ARGV && @ARGV%2==0;
+ Usage: $0 S1 T1 S2 T2...
+ to find if target string Tn may be obtained from the source string Sn
+ by a single permutation of two characters.
+ FIN
+for my($source, $target)(@ARGV){
+ say"$source $target -> ",
+ (my $joined="$source$;$target") # join source and target using special character
+ =~ # match to
+ /^ # start of source
+ (.*) # arbitrary string (group 1)
+ (.) # a single character to permute (group 2)
+ (.*) # arbitrary string (group 3)
+ (.) # second character to permute (group 4)
+ (.*) # arbitrary string (group 5)
+ $; # end of source
+ \1\4\3\2\5 # target is source with \2 and \4 permuted
+ $ # end of target
+ /x
+ ?"True":"False";
+}