aboutsummaryrefslogtreecommitdiff
path: root/challenge-081
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2020-10-13 11:25:01 +0800
committer冯昶 <seaker@qq.com>2020-10-13 11:25:01 +0800
commitfa2e628623cb8c8437ff27ffe231894c7593f777 (patch)
tree5bb9dffd9d818c08a781f417c2aeed5c555f49fb /challenge-081
parent19716bbb7f4f4ed50fba5776b439763d073f8bec (diff)
downloadperlweeklychallenge-club-fa2e628623cb8c8437ff27ffe231894c7593f777.tar.gz
perlweeklychallenge-club-fa2e628623cb8c8437ff27ffe231894c7593f777.tar.bz2
perlweeklychallenge-club-fa2e628623cb8c8437ff27ffe231894c7593f777.zip
challenge 081, raku solution
Diffstat (limited to 'challenge-081')
-rwxr-xr-xchallenge-081/feng-chang/raku/ch-1.raku19
-rwxr-xr-xchallenge-081/feng-chang/raku/ch-2.raku15
-rw-r--r--challenge-081/feng-chang/raku/input.txt3
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-081/feng-chang/raku/ch-1.raku b/challenge-081/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..3b0ddcd629
--- /dev/null
+++ b/challenge-081/feng-chang/raku/ch-1.raku
@@ -0,0 +1,19 @@
+#!/bin/env raku
+
+sub MAIN(Str:D $A, Str:D $B) {
+ my @answers;
+
+ my $lena = $A.chars;
+ my $lenb = $B.chars;
+ my $lenc = $lena gcd $lenb;
+
+ my Str $c = $A.substr(0, $lenc);
+ @answers.push($c) if $c x ($lena / $lenc) eq $A and $c x ($lenb / $lenc) eq $B;
+
+ for (1..$lenc/2).grep({ $lenc %% $_ }) -> $i {
+ my Str $d = $c.substr(0, $i);
+ @answers.push($d) if $d x ($lenc / $i) eq $c;
+ }
+
+ say @answers;
+}
diff --git a/challenge-081/feng-chang/raku/ch-2.raku b/challenge-081/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..8886eaee38
--- /dev/null
+++ b/challenge-081/feng-chang/raku/ch-2.raku
@@ -0,0 +1,15 @@
+#!/bin/env raku
+
+my regex omits { <[."(),]> | "'s" | "--" };
+my %freqs;
+
+'input.txt'.IO.slurp.subst(/<omits>/, ' ', :g).words.map:{ ++%freqs{$_} };
+
+my %voc;
+for %freqs.kv -> $k, $v {
+ %voc{$v}.push($k);
+}
+
+for %voc.keys.sort -> $k {
+ say "$k { %voc{$k}.join(' ') }";
+}
diff --git a/challenge-081/feng-chang/raku/input.txt b/challenge-081/feng-chang/raku/input.txt
new file mode 100644
index 0000000000..37001629ad
--- /dev/null
+++ b/challenge-081/feng-chang/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.