aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorboblied <boblied@gmail.com>2020-10-06 07:26:56 -0500
committerboblied <boblied@gmail.com>2020-10-06 07:26:56 -0500
commit8968a5ff21e13aecd34c6a0697358cfe1fd30a4d (patch)
tree7a45afa0f42be3e8e43d2aed9598e2a39d095fd2
parent89a288199348fb289086328e6b49d2151216cc6a (diff)
downloadperlweeklychallenge-club-8968a5ff21e13aecd34c6a0697358cfe1fd30a4d.tar.gz
perlweeklychallenge-club-8968a5ff21e13aecd34c6a0697358cfe1fd30a4d.tar.bz2
perlweeklychallenge-club-8968a5ff21e13aecd34c6a0697358cfe1fd30a4d.zip
Set up challenge 081
-rw-r--r--challenge-081/bob-lied/README4
-rwxr-xr-xchallenge-081/bob-lied/perl/ch-1.pl46
-rwxr-xr-xchallenge-081/bob-lied/perl/ch-2.pl46
-rw-r--r--challenge-081/bob-lied/perl/lib/CommonBaseString.pm39
-rw-r--r--challenge-081/bob-lied/perl/lib/FrequencySort.pm39
-rw-r--r--challenge-081/bob-lied/perl/t/CommonBaseString.t16
-rw-r--r--challenge-081/bob-lied/perl/t/FrequencySort.t16
-rw-r--r--challenge-081/bob-lied/perl/t/input13
8 files changed, 217 insertions, 2 deletions
diff --git a/challenge-081/bob-lied/README b/challenge-081/bob-lied/README
index 026576bd98..e698fa656a 100644
--- a/challenge-081/bob-lied/README
+++ b/challenge-081/bob-lied/README
@@ -1,3 +1,3 @@
-Solutions to weekly challenge 79 by Bob Lied.
+Solutions to weekly challenge 81 by Bob Lied.
-https://perlweeklychallenge.org/blog/perl-weekly-challenge-079/
+https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
diff --git a/challenge-081/bob-lied/perl/ch-1.pl b/challenge-081/bob-lied/perl/ch-1.pl
new file mode 100755
index 0000000000..3aa9ff13fe
--- /dev/null
+++ b/challenge-081/bob-lied/perl/ch-1.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# ch-1.pl
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Perl Weekly Challenge 081 Task #1 > Common Base String
+#=============================================================================
+# You are given 2 strings, $A and $B.
+# Write a script to find out common base strings in $A and $B.
+# A substring of a string $S is called base string if repeated concatenation
+# of the substring results in the string.
+# Example 1: Input: $A = "abcdabcd"
+# $B = "abcdabcdabcdabcd"
+# Output: ("abcd", "abcdabcd")
+#
+# Example 2: Input: $A = "aaa"
+# $B = "aa"
+# Output: ("a")
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+use Getopt::Long;
+
+use lib "lib";
+use CommonBaseString;
+
+sub Usage { "Usage: $0 astring bstring" };
+
+my $Verbose = 0;
+GetOptions('verbose' => \$Verbose);
+
+my (@A, @B) = @ARGV;
+
+die Usage() unless $A;
+die Usage() unless $B;
+
+my $cbs = CommonBaseString->new($A, $B);
+my $result = $cbs->run();
+say $result;
diff --git a/challenge-081/bob-lied/perl/ch-2.pl b/challenge-081/bob-lied/perl/ch-2.pl
new file mode 100755
index 0000000000..5ed37221ff
--- /dev/null
+++ b/challenge-081/bob-lied/perl/ch-2.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# ch-2.pl
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Perl Weekly Challenge 081 Task #2 > Frequency Sort
+#=============================================================================
+# You are given file named input.
+# Write a script to find the frequency of all the words.
+# It should print the result as first column of each line should be the
+# frequency of the the word followed by all the words of that frequency
+# arranged in lexicographical order. Also sort the words in the ascending
+# order of frequency.
+# For the sake of this task, please ignore the following in the input file:
+# . " ( ) , 's --
+# Keep hyphenated words and contractions, but reduce possessives to their base
+# (e.g., "award-winning" and "doesn't" are words, but "Joe's" becomes "Joe"
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+use Getopt::Long;
+
+use lib "lib";
+use FrequencySort;
+
+sub Usage { "Usage: $0 args" };
+
+my $Verbose = 0;
+GetOptions('verbose' => \$Verbose);
+
+my $arg = shift;
+my @list = @ARGV;
+
+die Usage() unless $arg;
+die Usage() unless @list;
+
+my $task = FrequencySort->new();
+my $result = $task->run();
+say $result;
diff --git a/challenge-081/bob-lied/perl/lib/CommonBaseString.pm b/challenge-081/bob-lied/perl/lib/CommonBaseString.pm
new file mode 100644
index 0000000000..b67ecfa948
--- /dev/null
+++ b/challenge-081/bob-lied/perl/lib/CommonBaseString.pm
@@ -0,0 +1,39 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# CommonBaseString.pm
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Description:
+#=============================================================================
+
+package CommonBaseString;
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw();
+our @EXPORT_OK = qw();
+
+sub new($class, $name1)
+{
+ $class = ref($class) || $class;
+ my $self = {
+ _name1 => $name1,
+ };
+ bless $self, $class;
+ return $self;
+}
+
+sub run($self)
+{
+ return undef;
+}
+
+1;
diff --git a/challenge-081/bob-lied/perl/lib/FrequencySort.pm b/challenge-081/bob-lied/perl/lib/FrequencySort.pm
new file mode 100644
index 0000000000..177e28ace9
--- /dev/null
+++ b/challenge-081/bob-lied/perl/lib/FrequencySort.pm
@@ -0,0 +1,39 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# FrequencySort.pm
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Description:
+#=============================================================================
+
+package FrequencySort;
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw();
+our @EXPORT_OK = qw();
+
+sub new($class, $name1)
+{
+ $class = ref($class) || $class;
+ my $self = {
+ _name1 => $name1,
+ };
+ bless $self, $class;
+ return $self;
+}
+
+sub run($self)
+{
+ return undef;
+}
+
+1;
diff --git a/challenge-081/bob-lied/perl/t/CommonBaseString.t b/challenge-081/bob-lied/perl/t/CommonBaseString.t
new file mode 100644
index 0000000000..81d4345b76
--- /dev/null
+++ b/challenge-081/bob-lied/perl/t/CommonBaseString.t
@@ -0,0 +1,16 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#
+#===============================================================================
+# FILE: CommonBaseString.t
+# DESCRIPTION: Unit test for CommonBaseString
+#===============================================================================
+
+use strict;
+use warnings;
+use v5.30;
+
+use Test2::V0;
+
+use CommonBaseString;
+
+done_testing();
diff --git a/challenge-081/bob-lied/perl/t/FrequencySort.t b/challenge-081/bob-lied/perl/t/FrequencySort.t
new file mode 100644
index 0000000000..794fd04750
--- /dev/null
+++ b/challenge-081/bob-lied/perl/t/FrequencySort.t
@@ -0,0 +1,16 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#
+#===============================================================================
+# FILE: FrequencySort.t
+# DESCRIPTION: Unit test for FrequencySort
+#===============================================================================
+
+use strict;
+use warnings;
+use v5.30;
+
+use Test2::V0;
+
+use FrequencySort;
+
+done_testing();
diff --git a/challenge-081/bob-lied/perl/t/input b/challenge-081/bob-lied/perl/t/input
new file mode 100644
index 0000000000..5905c36971
--- /dev/null
+++ b/challenge-081/bob-lied/perl/t/input
@@ -0,0 +1,13 @@
+West Side Story
+
+The award-winning adaptation of the classic romantic tragedy "Romeo and
+Juliet". The feuding families become two warring New York City gangs, the
+white Jets led by Riff and the Latino Sharks, led by Bernardo. Their hatred
+escalates to a point where neither can coexist with any form of understanding.
+But when Riff's best friend (and former Jet) Tony and Bernardo's younger
+sister Maria meet at a dance, no one can do anything to stop their love. Maria
+and Tony begin meeting in secret, planning to run away. Then the Sharks and
+Jets plan a rumble under the highway--whoever wins gains control of the
+streets. Maria sends Tony to stop it, hoping it can end the violence. It goes
+terribly wrong, and before the lovers know what's happened, tragedy strikes
+and doesn't stop until the climactic and heartbreaking ending.