diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-22 00:27:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 00:27:22 +0100 |
| commit | d8154dfc33ce0c554d75fe5fdedb5337d32742e5 (patch) | |
| tree | b44e94c764d5726dcf333d1c2e6f970100dd1e1c /challenge-331 | |
| parent | f0c338ac1b8758b423563edf45c4652e9658eb75 (diff) | |
| parent | a8609bdf63cf6d5f0780c676b5cf4d48ecd72cbb (diff) | |
| download | perlweeklychallenge-club-d8154dfc33ce0c554d75fe5fdedb5337d32742e5.tar.gz perlweeklychallenge-club-d8154dfc33ce0c554d75fe5fdedb5337d32742e5.tar.bz2 perlweeklychallenge-club-d8154dfc33ce0c554d75fe5fdedb5337d32742e5.zip | |
Merge pull request #12391 from wlmb/challenges
Solve PWC331
Diffstat (limited to 'challenge-331')
| -rw-r--r-- | challenge-331/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-331/wlmb/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-331/wlmb/perl/ch-2.pl | 27 |
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"; +} |
