aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-240/bob-lied/README6
-rw-r--r--challenge-240/bob-lied/blog.txt1
-rw-r--r--challenge-240/bob-lied/perl/ch-1.pl50
-rw-r--r--challenge-240/bob-lied/perl/ch-2.pl42
4 files changed, 96 insertions, 3 deletions
diff --git a/challenge-240/bob-lied/README b/challenge-240/bob-lied/README
index 770b310f25..152add2898 100644
--- a/challenge-240/bob-lied/README
+++ b/challenge-240/bob-lied/README
@@ -1,4 +1,4 @@
-Solutions to weekly challenge 239 by Bob Lied
+Solutions to weekly challenge 240 by Bob Lied
-https://perlweeklychallenge.org/blog/perl-weekly-challenge-239/
-https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-239/bob-lied
+https://perlweeklychallenge.org/blog/perl-weekly-challenge-240/
+https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-240/bob-lied
diff --git a/challenge-240/bob-lied/blog.txt b/challenge-240/bob-lied/blog.txt
new file mode 100644
index 0000000000..a836f78439
--- /dev/null
+++ b/challenge-240/bob-lied/blog.txt
@@ -0,0 +1 @@
+https://dev.to/boblied/pwc-240-just-a-slice-no-loop-please-ill-eat-it-here-3l0l
diff --git a/challenge-240/bob-lied/perl/ch-1.pl b/challenge-240/bob-lied/perl/ch-1.pl
new file mode 100644
index 0000000000..297dc52f9f
--- /dev/null
+++ b/challenge-240/bob-lied/perl/ch-1.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# ch-1.pl Perl Weekly Challenge 240 Task 1 Acronym
+#=============================================================================
+# Copyright (c) 2023, Bob Lied
+#=============================================================================
+# You are given an array of strings and a check string.
+# Write a script to find out if the check string is the acronym of the
+# words in the given array.
+# Example 1 Input: @str = ("Perl", "Python", "Pascal") $chk = "ppp"
+# Output: true
+# Example 2 Input: @str = ("Perl", "Raku") $chk = "rp"
+# Output: false
+# Example 3 Input: @str = ("Oracle", "Awk", "C") $chk = "oac"
+# Output: true
+#=============================================================================
+
+use v5.38;
+use builtin qw/true false/; no warnings "experimental::builtin";
+
+use Getopt::Long;
+my $Verbose = 0;
+my $DoTest = 0;
+
+my $Check = "";
+
+GetOptions("check:s" => \$Check, "test" => \$DoTest, "verbose" => \$Verbose);
+exit(!runTest()) if $DoTest;
+
+die "Usage: $0 -c check stringlist..." unless $Check and @ARGV > 0;
+
+say acronym($Check, @ARGV) ? "true" : "false";
+
+sub acronym($chk, @str)
+{
+ return $chk eq join("", map { lc substr($_, 0, 1) } @str)
+}
+
+sub runTest
+{
+ use Test2::V0;
+ use builtin qw/false true/; no warnings "experimental::builtin";
+
+ is( acronym( "ppp", qw(Perl Python Pascal)), true, "Example 1");
+ is( acronym( "rp" , qw(Perl Raku )), false, "Example 2");
+ is( acronym( "oac", qw(Oracle Awk C )), true, "Example 3");
+
+ done_testing;
+}
diff --git a/challenge-240/bob-lied/perl/ch-2.pl b/challenge-240/bob-lied/perl/ch-2.pl
new file mode 100644
index 0000000000..855742b6cc
--- /dev/null
+++ b/challenge-240/bob-lied/perl/ch-2.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# ch-2.pl Perl Weekly Challenge 240 Task 2 Build Array
+#=============================================================================
+# Copyright (c) 2023, Bob Lied
+#=============================================================================
+# You are given an array of integers.
+# Write a script to create an array such that new[i] = old[old[i]]
+# where 0 <= i < new.length.
+# Example 1 Input: @int = (0, 2, 1, 5, 3, 4)
+# Output: (0, 1, 2, 4, 5, 3)
+# Example 2 Input: @int = (5, 0, 1, 2, 3, 4)
+# Output: (4, 5, 0, 1, 2, 3)
+#=============================================================================
+
+use v5.38;
+
+use Getopt::Long;
+my $Verbose = 0;
+my $DoTest = 0;
+
+GetOptions("test" => \$DoTest, "verbose" => \$Verbose);
+exit(!runTest()) if $DoTest;
+
+say "(", join(", ", buildArray(@ARGV)->@*), ")";
+
+sub buildArray(@int)
+{
+
+ return [ @int[@int] ];
+}
+
+sub runTest
+{
+ use Test2::V0;
+
+ is( buildArray(0,2,1,5,3,4), [0,1,2,4,5,3], "Example 1");
+ is( buildArray(5,0,1,2,3,4), [4,5,0,1,2,3], "Example 2");
+
+ done_testing;
+}