aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-11 18:49:38 +0100
committerGitHub <noreply@github.com>2020-10-11 18:49:38 +0100
commitea0754b2a5b60f7347ae4bf841349c89453d34c5 (patch)
tree91910f3cd3304524a54d487e79725b34bfb30540
parent4cfb38d4068f3727d0bf1a1a1b90367d49bbd3a7 (diff)
parent2fabcb18b2e0ba4cb868448e69183ab681801167 (diff)
downloadperlweeklychallenge-club-ea0754b2a5b60f7347ae4bf841349c89453d34c5.tar.gz
perlweeklychallenge-club-ea0754b2a5b60f7347ae4bf841349c89453d34c5.tar.bz2
perlweeklychallenge-club-ea0754b2a5b60f7347ae4bf841349c89453d34c5.zip
Merge pull request #2493 from ash/master
Raku solutions 081-1 and 081-2 by ash.
-rw-r--r--challenge-081/ash/raku/ch-1.raku23
-rw-r--r--challenge-081/ash/raku/ch-2.raku22
-rw-r--r--challenge-081/ash/raku/input.txt3
3 files changed, 48 insertions, 0 deletions
diff --git a/challenge-081/ash/raku/ch-1.raku b/challenge-081/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..229683ac83
--- /dev/null
+++ b/challenge-081/ash/raku/ch-1.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+#
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
+
+# Test run:
+#
+# $ raku ch-1.raku abcdabcd abcdabcdabcdabcd
+# abcd
+# abcdabcd
+
+unit sub MAIN(Str $a is copy, Str $b is copy);
+
+# Make sure that $a is not longer than $b
+($a, $b) = $b, $a if $a.chars > $b.chars;
+
+for 1 .. $a.chars -> $n {
+ next unless $a.chars %% $n && $b.chars %% $n;
+
+ my $c = $a.substr(0, $n);
+
+ say $c if $c x ($a.chars / $n) eq $a && $c x ($b.chars / $n) eq $b;
+}
diff --git a/challenge-081/ash/raku/ch-2.raku b/challenge-081/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..09ad4b4210
--- /dev/null
+++ b/challenge-081/ash/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+#
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
+
+# Run:
+# $ raku ch-2.raku
+
+my $text = 'input.txt'.IO.slurp;
+
+my %freq;
+%freq{$_}++ for $text ~~ m:g/(\w+)/;
+
+my @freq = %freq.values.unique.sort;
+
+my @output;
+for @freq -> $freq {
+ my @words = (%freq.grep: *.value == $freq).map: *.key;
+ @output.push: ($freq, @words.sort).join: ' ';
+}
+
+@output.join("\n\n").say;
diff --git a/challenge-081/ash/raku/input.txt b/challenge-081/ash/raku/input.txt
new file mode 100644
index 0000000000..37001629ad
--- /dev/null
+++ b/challenge-081/ash/raku/input.txt
@@ -0,0 +1,3 @@
+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.