aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-081/jaldhar-h-vyas/blog.txt1
-rw-r--r--challenge-081/jaldhar-h-vyas/input8
-rwxr-xr-xchallenge-081/jaldhar-h-vyas/perl/ch-1.pl21
-rwxr-xr-xchallenge-081/jaldhar-h-vyas/perl/ch-2.pl57
-rwxr-xr-xchallenge-081/jaldhar-h-vyas/raku/ch-1.p619
-rwxr-xr-xchallenge-081/jaldhar-h-vyas/raku/ch-2.p638
6 files changed, 144 insertions, 0 deletions
diff --git a/challenge-081/jaldhar-h-vyas/blog.txt b/challenge-081/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..f7951b8e03
--- /dev/null
+++ b/challenge-081/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2020/10/perl_weekly_challenge_week_81.html
diff --git a/challenge-081/jaldhar-h-vyas/input b/challenge-081/jaldhar-h-vyas/input
new file mode 100644
index 0000000000..de74f250ba
--- /dev/null
+++ b/challenge-081/jaldhar-h-vyas/input
@@ -0,0 +1,8 @@
+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. \ No newline at end of file
diff --git a/challenge-081/jaldhar-h-vyas/perl/ch-1.pl b/challenge-081/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..b769398ab0
--- /dev/null
+++ b/challenge-081/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+
+my ($A, $B) = @ARGV;
+
+my ($smaller, $larger) = length $A < length $B ? ($A, $B) : ($B, $A);
+my @base_strings;
+
+for my $c (1 .. length $smaller) {
+ if ((length $larger) % $c == 0) {
+ my $l = $larger;
+ my $s = substr $smaller, 0, $c;
+ $l =~ s/ $s //gmsx;
+ if ($l eq q{}) {
+ push @base_strings, $s;
+ }
+ }
+}
+
+say q{(}, (join q{ }, sort @base_strings), q{)};
diff --git a/challenge-081/jaldhar-h-vyas/perl/ch-2.pl b/challenge-081/jaldhar-h-vyas/perl/ch-2.pl
new file mode 100755
index 0000000000..0393107f9d
--- /dev/null
+++ b/challenge-081/jaldhar-h-vyas/perl/ch-2.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+use 5.020;
+use warnings;
+use English qw/ -no_match_vars /;
+
+sub readText {
+ my ($filename) = @_;
+ my $text;
+
+ open my $fh, '<', $filename or die "$OS_ERROR\n";
+ local $RS = undef;
+ $text = <$fh>;
+ close $fh;
+
+ return $text;
+}
+
+sub removePunctuation {
+ my ($text) = @_;
+
+ $text =~ s/ \. | " | \( | \) | , | 's | --/ /gmsx;
+
+ return $text;
+}
+
+sub countWords {
+ my ($text) = @_;
+ my %count;
+ my @words = split /\s+/, $text;
+
+ for my $word (@words) {
+ $count{$word}++;
+ }
+
+ return \%count;
+}
+
+sub display {
+ my ($count) = @_;
+ my %frequency;
+
+ map {push @{$frequency{$count->{$_}}}, $_; } sort keys %{$count};
+
+ for my $key (sort keys %frequency) {
+ say "$key ", (join q{ }, @{$frequency{$key}}), "\n";
+ }
+}
+
+display(
+ countWords(
+ removePunctuation(
+ readText(
+ './input'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/challenge-081/jaldhar-h-vyas/raku/ch-1.p6 b/challenge-081/jaldhar-h-vyas/raku/ch-1.p6
new file mode 100755
index 0000000000..ca77f99f9d
--- /dev/null
+++ b/challenge-081/jaldhar-h-vyas/raku/ch-1.p6
@@ -0,0 +1,19 @@
+#!/usr/bin/perl6
+
+sub MAIN(*$A, *$B) {
+ my ($smaller, $larger) = $A.chars < $B.chars ?? ($A, $B) !! ($B, $A);
+ my @base_strings;
+
+ for 1 .. $smaller.chars -> $c {
+ if ($larger.chars %% $c) {
+ my $l = $larger;
+ my $s = $smaller.substr(0, $c);
+ $l ~~ s:g/ $s //;
+ if ($l eq q{}) {
+ @base_strings.push($s);
+ }
+ }
+ }
+
+ say sort @base_strings;
+} \ No newline at end of file
diff --git a/challenge-081/jaldhar-h-vyas/raku/ch-2.p6 b/challenge-081/jaldhar-h-vyas/raku/ch-2.p6
new file mode 100755
index 0000000000..233fee66a2
--- /dev/null
+++ b/challenge-081/jaldhar-h-vyas/raku/ch-2.p6
@@ -0,0 +1,38 @@
+#!/usr/bin/perl6
+
+sub readText($filename) {
+ my $text;
+
+ return $filename.IO.slurp;
+}
+
+sub removePunctuation($text) {
+ my $processed = $text;
+
+ $processed ~~ s:g/ '.' | '"' | '(' | ')' | ',' | "'s" | '--'/ /;
+
+ return $processed;
+}
+
+sub countWords($text) {
+ my %count = $text.split( /\s+/ ).classify({ $_; });
+ return %count.keys.map({ %count{$_}.elems => $_; });
+}
+
+sub display(@count) {
+ my %frequency;
+
+ @count.sort.map({ %frequency{$_.key}.push($_.value); });
+
+ %frequency.keys.sort.map({
+ say "$_ ", %frequency{$_}.join(q{ }), "\n";
+ });
+}
+
+sub MAIN() {
+ readText('./input')
+ ==> removePunctuation()
+ ==> countWords()
+ ==> display()
+ ;
+} \ No newline at end of file