diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-04 11:06:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-04 11:06:58 +0100 |
| commit | e4b4e44838b1133b77013bc7da90fc238b4e5485 (patch) | |
| tree | 5d1b2631e44f19c84fc7775ccf5e48f7b4e1e77e /challenge-272 | |
| parent | 2dcd88795f4e8ce376e5af1c987b4ed5d62b76b4 (diff) | |
| parent | d50ea9f9f461bcec9d50bd7cb0481576553393b0 (diff) | |
| download | perlweeklychallenge-club-e4b4e44838b1133b77013bc7da90fc238b4e5485.tar.gz perlweeklychallenge-club-e4b4e44838b1133b77013bc7da90fc238b4e5485.tar.bz2 perlweeklychallenge-club-e4b4e44838b1133b77013bc7da90fc238b4e5485.zip | |
Merge pull request #10201 from wlmb/challenges
Solve PWC272
Diffstat (limited to 'challenge-272')
| -rw-r--r-- | challenge-272/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-272/wlmb/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-272/wlmb/perl/ch-2.pl | 19 |
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-272/wlmb/blog.txt b/challenge-272/wlmb/blog.txt new file mode 100644 index 0000000000..96f79fd181 --- /dev/null +++ b/challenge-272/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/06/03/PWC272/ diff --git a/challenge-272/wlmb/perl/ch-1.pl b/challenge-272/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..ffa55487ca --- /dev/null +++ b/challenge-272/wlmb/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Perl weekly challenge 272 +# Task 1: Defang IP Address +# +# See https://wlmb.github.io/2024/06/03/PWC272/#task-1-defang-ip-address +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 A1 A2... + to defang the IP addresses A1 A2... + FIN +my $ip=join '\.', ('\d{1,3}') x 4; +for(@ARGV){ + my $original=$_; + warn "Not a valid IP: $_", next unless /^$ip$/; + s/\./[.]/g; + say "$original -> $_"; +} diff --git a/challenge-272/wlmb/perl/ch-2.pl b/challenge-272/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..24c68607a0 --- /dev/null +++ b/challenge-272/wlmb/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# Perl weekly challenge 272 +# Task 2: String Score +# +# See https://wlmb.github.io/2024/06/03/PWC272/#task-2-string-score +use v5.36; +use PDL; +use PDL::NiceSlice; +die <<~"FIN" unless @ARGV; + Usage: $0 S1 S2... + to find the score of the strings S1 S2... + i.e., the sum of the absolute value of + the difference of consecutive ascii values. + FIN +for(@ARGV){ + my $ords=pdl map {ord} split ""; + warn "Need at least two characters: $_", next unless $ords->nelem > 1; + say "$_ -> ",($ords(1:-1)-$ords(0:-2))->abs->sumover; +} |
