aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-06-03 16:03:14 -0400
committerDave Jacoby <jacoby.david@gmail.com>2024-06-03 16:03:14 -0400
commit9389727a0e5905882dbf2805d8ae4efcd579fed4 (patch)
treed88ca2d73d4d22a317f3d517d227799da4b4e4f3
parent6b1c67381886ee30e0dd9f9356340350101139b8 (diff)
downloadperlweeklychallenge-club-9389727a0e5905882dbf2805d8ae4efcd579fed4.tar.gz
perlweeklychallenge-club-9389727a0e5905882dbf2805d8ae4efcd579fed4.tar.bz2
perlweeklychallenge-club-9389727a0e5905882dbf2805d8ae4efcd579fed4.zip
DAJ 272
-rw-r--r--challenge-272/dave-jacoby/perl/ch-1.pl24
-rw-r--r--challenge-272/dave-jacoby/perl/ch-2.pl25
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-272/dave-jacoby/perl/ch-1.pl b/challenge-272/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..abaa466aae
--- /dev/null
+++ b/challenge-272/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ bitwise fc postderef say signatures state };
+
+use List::Util qw{max};
+
+my @examples = (
+
+ "1.1.1.1", "255.101.1.0"
+);
+for my $example (@examples) {
+ my $output = defang_ipv4($example);
+ say <<"END";
+ Input: \$ip = "$example"
+ Output: "$output"
+END
+}
+
+sub defang_ipv4 ( $address ) {
+ $address =~ s/\./[.]/gmx;
+ return $address;
+}
diff --git a/challenge-272/dave-jacoby/perl/ch-2.pl b/challenge-272/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..79650b52d9
--- /dev/null
+++ b/challenge-272/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ fc say postderef signatures state };
+
+use List::Util qw{ sum0 };
+
+my @examples = (qw{ hello perl raku weekly linux Perl PERL });
+
+for my $example (@examples) {
+ my $output = string_score($example);
+
+ say <<"END";
+ Input: \$str = "$example"
+ Output: $output
+END
+}
+
+sub string_score ($str) {
+ my @str = split //, $str;
+ return sum0
+ map { abs ord( $str[$_] ) - ord( $str[ 1 + $_ ] ) }
+ 0 .. -2 + scalar @str;
+}