aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2020-10-05 09:18:20 +0000
committerNiels van Dijke <perlboy@cpan.org>2020-10-05 09:18:20 +0000
commitc798d022f09d8cc993de16872599da96f2607136 (patch)
tree02473e6d0347d81808d445401aca94140a148d9a
parentcef248ba491398a30061ba49fbc2a824116ae996 (diff)
downloadperlweeklychallenge-club-c798d022f09d8cc993de16872599da96f2607136.tar.gz
perlweeklychallenge-club-c798d022f09d8cc993de16872599da96f2607136.tar.bz2
perlweeklychallenge-club-c798d022f09d8cc993de16872599da96f2607136.zip
Task 1 & 2
-rwxr-xr-xchallenge-081/perlboy1967/perl/ch-1.pl30
-rwxr-xr-xchallenge-081/perlboy1967/perl/ch-2.pl27
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-081/perlboy1967/perl/ch-1.pl b/challenge-081/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..5c131f3543
--- /dev/null
+++ b/challenge-081/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+# Perl Weekly Challenge - 081
+# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
+#
+# Task 1 - Common Base String
+#
+# Author: Niels 'PerlBoy' van Dijke
+
+use strict;
+use warnings;
+
+@ARGV = qw(abcdabcd abcdabcdabcdabcd)
+ unless (scalar @ARGV >= 2);
+
+my ($A, $B) = @ARGV;
+
+my @output;
+foreach my $l (1 .. length($A)) {
+ my $substr = substr($A, 0, $l);
+ push(@output, $substr)
+ if ($B =~ m#($substr)($substr)#);
+}
+
+printf "Input:\n";
+printf "\t\$A = '%s'\n", $A;
+printf "\t\$B = '%s'\n", $B;
+printf "\n";
+printf "Output:\n";
+printf "\t(%s)\n",(scalar @output ? '"'.join('","', @output).'"' : 'undef');
diff --git a/challenge-081/perlboy1967/perl/ch-2.pl b/challenge-081/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..ca7d54d5dc
--- /dev/null
+++ b/challenge-081/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# Perl Weekly Challenge - 081
+# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
+#
+# Task 2 - Frequency Sort
+#
+# Author: Niels 'PerlBoy' van Dijke
+
+use strict;
+use warnings;
+
+use List::Util qw(min max);
+use List::MoreUtils qw(uniq);
+
+my $input = qq(
+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.
+);
+
+my %input;
+
+map { $input{$_}++ } grep /../, split(/[^A-Za-z]+/, $input);
+foreach my $count (sort { $a <=> $b } uniq(values %input)) {
+ printf "$count %s\n", join(' ', sort grep { $input{$_} == $count } keys %input);
+}