diff options
| author | arnesom <arne@bbop.org> | 2020-10-11 20:10:32 +0200 |
|---|---|---|
| committer | arnesom <arne@bbop.org> | 2020-10-11 20:10:32 +0200 |
| commit | 2772d65087662281c7c5ec2d47014efda7e8d59f (patch) | |
| tree | 56d7356a8d5c70ef57f16f3180d8c8c6a76f627a | |
| parent | 1a8d65ead60462406e8b74d8b6298646f2b7d3d7 (diff) | |
| download | perlweeklychallenge-club-2772d65087662281c7c5ec2d47014efda7e8d59f.tar.gz perlweeklychallenge-club-2772d65087662281c7c5ec2d47014efda7e8d59f.tar.bz2 perlweeklychallenge-club-2772d65087662281c7c5ec2d47014efda7e8d59f.zip | |
Arne Sommer
| -rw-r--r-- | challenge-081/arne-sommer/blog.txt | 2 | ||||
| -rwxr-xr-x | challenge-081/arne-sommer/raku/ch-1.p6 | 23 | ||||
| -rwxr-xr-x | challenge-081/arne-sommer/raku/ch-2.p6 | 11 | ||||
| -rwxr-xr-x | challenge-081/arne-sommer/raku/common-base-string | 23 | ||||
| -rwxr-xr-x | challenge-081/arne-sommer/raku/frequency-sort | 19 | ||||
| -rwxr-xr-x | challenge-081/arne-sommer/raku/frequency-sort-map | 11 | ||||
| -rwxr-xr-x | challenge-081/arne-sommer/raku/frequency-sort-postfix | 13 | ||||
| -rw-r--r-- | challenge-081/arne-sommer/raku/input.txt | 3 |
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. |
