aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-11 19:58:14 +0100
committerGitHub <noreply@github.com>2020-10-11 19:58:14 +0100
commitdfc9fbf91598a1cddf347f0a9af65fecd0135bec (patch)
tree1e6cb4a762135227845a96af134ced23ff762d1f
parentc5b0010f1c4cf28ee945bb9dd8f4f2a2172a88c9 (diff)
parent2772d65087662281c7c5ec2d47014efda7e8d59f (diff)
downloadperlweeklychallenge-club-dfc9fbf91598a1cddf347f0a9af65fecd0135bec.tar.gz
perlweeklychallenge-club-dfc9fbf91598a1cddf347f0a9af65fecd0135bec.tar.bz2
perlweeklychallenge-club-dfc9fbf91598a1cddf347f0a9af65fecd0135bec.zip
Merge pull request #2495 from arnesom/branch-for-challenge-081
Arne Sommer
-rw-r--r--challenge-081/arne-sommer/blog.txt2
-rwxr-xr-xchallenge-081/arne-sommer/raku/ch-1.p623
-rwxr-xr-xchallenge-081/arne-sommer/raku/ch-2.p611
-rwxr-xr-xchallenge-081/arne-sommer/raku/common-base-string23
-rwxr-xr-xchallenge-081/arne-sommer/raku/frequency-sort19
-rwxr-xr-xchallenge-081/arne-sommer/raku/frequency-sort-map11
-rwxr-xr-xchallenge-081/arne-sommer/raku/frequency-sort-postfix13
-rw-r--r--challenge-081/arne-sommer/raku/input.txt3
8 files changed, 105 insertions, 0 deletions
diff --git a/challenge-081/arne-sommer/blog.txt b/challenge-081/arne-sommer/blog.txt
new file mode 100644
index 0000000000..12b5f6c13b
--- /dev/null
+++ b/challenge-081/arne-sommer/blog.txt
@@ -0,0 +1,2 @@
+https://raku-musings.com/common-frequency.html
+
diff --git a/challenge-081/arne-sommer/raku/ch-1.p6 b/challenge-081/arne-sommer/raku/ch-1.p6
new file mode 100755
index 0000000000..b99af78b6e
--- /dev/null
+++ b/challenge-081/arne-sommer/raku/ch-1.p6
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (Str $A where $A.chars > 0, Str $B where $B.chars > 0, :v(:$verbose));
+
+die "Different characters in A and B"
+ unless $A.comb.unique.sort.join eq $B.comb.unique.sort.join;
+
+my $a = $A.chars;
+my $b = $B.chars;
+
+my $unique = $A.comb.unique.elems;
+
+my @cbs;
+
+for $unique .. min($a, $b) -> $length
+{
+ my $c = $A.substr(0, $length);
+ say ": Length: $length -> $c" if $verbose;
+
+ @cbs.push: $c if $c x ($a / $length) eq $A && $c x ($b / $length) eq $B;
+}
+
+say '(' ~ @cbs.map({ '"' ~ $_ ~ '"' }).join(", ") ~ ')' if @cbs;
diff --git a/challenge-081/arne-sommer/raku/ch-2.p6 b/challenge-081/arne-sommer/raku/ch-2.p6
new file mode 100755
index 0000000000..0bb2cc3965
--- /dev/null
+++ b/challenge-081/arne-sommer/raku/ch-2.p6
@@ -0,0 +1,11 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($file where $file.IO.e && $file.IO.r = "input.txt");
+
+my %freq = $file.IO.slurp.trans(/<[."(),]>/ => ' ').subst("'s", " ", :global).subst("--", " ", :global).words.Bag;
+
+my @freq;
+
+%freq.keys.sort.map({ @freq[%freq{$_}] ~= $_ ~ " " });
+
+@freq.keys.grep({ @freq[$_] }).map({ say "$_ { @freq[$_] }" });
diff --git a/challenge-081/arne-sommer/raku/common-base-string b/challenge-081/arne-sommer/raku/common-base-string
new file mode 100755
index 0000000000..b99af78b6e
--- /dev/null
+++ b/challenge-081/arne-sommer/raku/common-base-string
@@ -0,0 +1,23 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (Str $A where $A.chars > 0, Str $B where $B.chars > 0, :v(:$verbose));
+
+die "Different characters in A and B"
+ unless $A.comb.unique.sort.join eq $B.comb.unique.sort.join;
+
+my $a = $A.chars;
+my $b = $B.chars;
+
+my $unique = $A.comb.unique.elems;
+
+my @cbs;
+
+for $unique .. min($a, $b) -> $length
+{
+ my $c = $A.substr(0, $length);
+ say ": Length: $length -> $c" if $verbose;
+
+ @cbs.push: $c if $c x ($a / $length) eq $A && $c x ($b / $length) eq $B;
+}
+
+say '(' ~ @cbs.map({ '"' ~ $_ ~ '"' }).join(", ") ~ ')' if @cbs;
diff --git a/challenge-081/arne-sommer/raku/frequency-sort b/challenge-081/arne-sommer/raku/frequency-sort
new file mode 100755
index 0000000000..2b9ec5b0b4
--- /dev/null
+++ b/challenge-081/arne-sommer/raku/frequency-sort
@@ -0,0 +1,19 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($file where $file.IO.e && $file.IO.r = "input.txt");
+
+my $content = $file.IO.slurp.trans(/<[."(),]>/ => ' ').subst("'s", " ", :global).subst("--", " ", :global);
+
+my %freq = $content.words.Bag;
+
+my @freq;
+
+for %freq.keys.sort -> $word
+{
+ @freq[%freq{$word}] ~= $word ~ " "
+}
+
+for @freq.keys -> $freq
+{
+ say "$freq " ~ @freq[$freq] if @freq[$freq];
+}
diff --git a/challenge-081/arne-sommer/raku/frequency-sort-map b/challenge-081/arne-sommer/raku/frequency-sort-map
new file mode 100755
index 0000000000..0bb2cc3965
--- /dev/null
+++ b/challenge-081/arne-sommer/raku/frequency-sort-map
@@ -0,0 +1,11 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($file where $file.IO.e && $file.IO.r = "input.txt");
+
+my %freq = $file.IO.slurp.trans(/<[."(),]>/ => ' ').subst("'s", " ", :global).subst("--", " ", :global).words.Bag;
+
+my @freq;
+
+%freq.keys.sort.map({ @freq[%freq{$_}] ~= $_ ~ " " });
+
+@freq.keys.grep({ @freq[$_] }).map({ say "$_ { @freq[$_] }" });
diff --git a/challenge-081/arne-sommer/raku/frequency-sort-postfix b/challenge-081/arne-sommer/raku/frequency-sort-postfix
new file mode 100755
index 0000000000..1abba1e403
--- /dev/null
+++ b/challenge-081/arne-sommer/raku/frequency-sort-postfix
@@ -0,0 +1,13 @@
+#! /usr/bin/env raku
+
+unit sub MAIN ($file where $file.IO.e && $file.IO.r = "input.txt");
+
+my $content = $file.IO.slurp.trans(/<[."(),]>/ => ' ').subst("'s", " ", :global).subst("--", " ", :global);
+
+my %freq = $content.words.Bag;
+
+my @freq;
+
+@freq[%freq{$_}] ~= $_ ~ " " for %freq.keys.sort;
+
+say "$_ { @freq[$_] }" for @freq.keys.grep({ @freq[$_] });
diff --git a/challenge-081/arne-sommer/raku/input.txt b/challenge-081/arne-sommer/raku/input.txt
new file mode 100644
index 0000000000..37001629ad
--- /dev/null
+++ b/challenge-081/arne-sommer/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.