From 2fabcb18b2e0ba4cb868448e69183ab681801167 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Sun, 11 Oct 2020 17:44:41 +0200 Subject: Raku solutions 081-1 and 081-2 by ash. --- challenge-081/ash/raku/ch-1.raku | 23 +++++++++++++++++++++++ challenge-081/ash/raku/ch-2.raku | 22 ++++++++++++++++++++++ challenge-081/ash/raku/input.txt | 3 +++ 3 files changed, 48 insertions(+) create mode 100644 challenge-081/ash/raku/ch-1.raku create mode 100644 challenge-081/ash/raku/ch-2.raku create mode 100644 challenge-081/ash/raku/input.txt 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. -- cgit