aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2024-06-03 07:04:39 -0600
committerLuis Mochan <mochan@fis.unam.mx>2024-06-03 07:04:39 -0600
commitd50ea9f9f461bcec9d50bd7cb0481576553393b0 (patch)
tree80030a9f502947a7935482787376f211ef8c50ba
parent6b1c67381886ee30e0dd9f9356340350101139b8 (diff)
downloadperlweeklychallenge-club-d50ea9f9f461bcec9d50bd7cb0481576553393b0.tar.gz
perlweeklychallenge-club-d50ea9f9f461bcec9d50bd7cb0481576553393b0.tar.bz2
perlweeklychallenge-club-d50ea9f9f461bcec9d50bd7cb0481576553393b0.zip
Solve PWC272
-rw-r--r--challenge-272/wlmb/blog.txt1
-rwxr-xr-xchallenge-272/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-272/wlmb/perl/ch-2.pl19
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;
+}