aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-272/bob-lied/README6
-rw-r--r--challenge-272/bob-lied/perl/ch-1.pl37
-rw-r--r--challenge-272/bob-lied/perl/ch-2.pl53
3 files changed, 93 insertions, 3 deletions
diff --git a/challenge-272/bob-lied/README b/challenge-272/bob-lied/README
index 968a88eea0..ebf6fe8695 100644
--- a/challenge-272/bob-lied/README
+++ b/challenge-272/bob-lied/README
@@ -1,4 +1,4 @@
-Solutions to weekly challenge 271 by Bob Lied
+Solutions to weekly challenge 272 by Bob Lied
-https://perlweeklychallenge.org/blog/perl-weekly-challenge-271/
-https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-271/bob-lied
+https://perlweeklychallenge.org/blog/perl-weekly-challenge-272/
+https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-272/bob-lied
diff --git a/challenge-272/bob-lied/perl/ch-1.pl b/challenge-272/bob-lied/perl/ch-1.pl
new file mode 100644
index 0000000000..a936481f97
--- /dev/null
+++ b/challenge-272/bob-lied/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# Copyright (c) 2024, Bob Lied
+#=============================================================================
+# ch-1.pl Perl Weekly Challenge 272 Task 1 Defang IP Address
+#=============================================================================
+#
+#=============================================================================
+
+use v5.38;
+
+use builtin qw/true false/; no warnings "experimental::builtin";
+
+use Getopt::Long;
+my $Verbose = 0;
+my $DoTest = 0;
+
+GetOptions("test" => \$DoTest, "verbose" => \$Verbose);
+exit(!runTest()) if $DoTest;
+
+say defangIP($_) for @ARGV;
+
+sub defangIP($ip)
+{
+ $ip =~ s/\./[.]/gr;
+}
+
+sub runTest
+{
+ use Test2::V0;
+
+ is( defangIP("1.1.1.1"), "1[.]1[.]1[.]1", "Example 1");
+ is( defangIP("255.101.1.0"), "255[.]101[.]1[.]0", "Example 2");
+
+ done_testing;
+}
diff --git a/challenge-272/bob-lied/perl/ch-2.pl b/challenge-272/bob-lied/perl/ch-2.pl
new file mode 100644
index 0000000000..1d586d83aa
--- /dev/null
+++ b/challenge-272/bob-lied/perl/ch-2.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# Copyright (c) 2024, Bob Lied
+#=============================================================================
+# ch-2.pl Perl Weekly Challenge 272 Task 2 String Score
+#=============================================================================
+#
+#=============================================================================
+
+use v5.38;
+
+use builtin qw/true false/; no warnings "experimental::builtin";
+
+use Getopt::Long;
+my $Verbose = 0;
+my $DoTest = 0;
+
+GetOptions("test" => \$DoTest, "verbose" => \$Verbose);
+exit(!runTest()) if $DoTest;
+
+say stringScore($_) for @ARGV;
+
+sub stringScore($str)
+{
+ my @v = map { ord($_) } split(//, $str);
+
+ my $score = 0;
+ my $first = shift @v;
+ while ( @v )
+ {
+ my $second = shift @v;
+ $score += abs($first - $second);
+ $first = $second;
+ }
+
+ return $score;
+}
+
+sub runTest
+{
+ use Test2::V0;
+
+ is( stringScore("hello"), 13, "Example 1");
+ is( stringScore("perl"), 30, "Example 2");
+ is( stringScore("raku"), 37, "Example 3");
+
+ is( stringScore(""), 0, "Empty string");
+ is( stringScore("R"), 0, "length 1 string");
+ is( stringScore("LLL"), 0, "repeated letters");
+
+ done_testing;
+}