aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-06 06:08:46 +0100
committerGitHub <noreply@github.com>2020-10-06 06:08:46 +0100
commit449d433ea7c017e0b5aaa50a948897c7fe2730cb (patch)
tree1388d5b0a3125ffcd4767d43c21a4aa3464a0e15
parenta712860040e843fe6a46e6ccd5d0b8ea02ded528 (diff)
parentc798d022f09d8cc993de16872599da96f2607136 (diff)
downloadperlweeklychallenge-club-449d433ea7c017e0b5aaa50a948897c7fe2730cb.tar.gz
perlweeklychallenge-club-449d433ea7c017e0b5aaa50a948897c7fe2730cb.tar.bz2
perlweeklychallenge-club-449d433ea7c017e0b5aaa50a948897c7fe2730cb.zip
Merge pull request #2455 from PerlBoy1967/branch-for-challenge-081
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);
+}