From 2a7f54ab092f795e9e88613f6e48b4d794a8c99d Mon Sep 17 00:00:00 2001 From: Julio Date: Tue, 6 Oct 2020 17:44:56 +0200 Subject: Add solution for week 81 --- challenge-081/juliodcs/perl/ch-1.pl | 6 ++++++ challenge-081/juliodcs/perl/ch-2.pl | 19 +++++++++++++++++++ challenge-081/juliodcs/perl/input | 3 +++ challenge-081/juliodcs/raku/ch-1.raku | 3 +++ challenge-081/juliodcs/raku/ch-2.raku | 15 +++++++++++++++ challenge-081/juliodcs/raku/input | 3 +++ 6 files changed, 49 insertions(+) create mode 100644 challenge-081/juliodcs/perl/ch-1.pl create mode 100644 challenge-081/juliodcs/perl/ch-2.pl create mode 100644 challenge-081/juliodcs/perl/input create mode 100644 challenge-081/juliodcs/raku/ch-1.raku create mode 100644 challenge-081/juliodcs/raku/ch-2.raku create mode 100644 challenge-081/juliodcs/raku/input diff --git a/challenge-081/juliodcs/perl/ch-1.pl b/challenge-081/juliodcs/perl/ch-1.pl new file mode 100644 index 0000000000..199408a21f --- /dev/null +++ b/challenge-081/juliodcs/perl/ch-1.pl @@ -0,0 +1,6 @@ +use strict; +use warnings; +use feature 'say'; +use List::MoreUtils 'uniq'; + +say for uniq map { /^(.+)\1+$/; $1 // () } @ARGV; diff --git a/challenge-081/juliodcs/perl/ch-2.pl b/challenge-081/juliodcs/perl/ch-2.pl new file mode 100644 index 0000000000..92b58fe97b --- /dev/null +++ b/challenge-081/juliodcs/perl/ch-2.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use File::Slurp; +use List::AllUtils qw(reduce uniq); +use Const::Fast; +use experimental 'signatures'; + +const my $rx_words => qr/ + (?-\p{L}+)* # Match dash-separated words + (?>'(?!s\b)\p{L}+)? # It may end with 「'」 + word (except for 「's」) +/ix; +const my @words => read_file('input') =~ m/$rx_words/g; +const my %scores => %{ +reduce { $a->{$b}++; $a } {}, @words }; +const my $add => sub($h, $w) { push $h->{$scores{$w}}->@*, $w; $h }; +const my %inverse => %{ +reduce { $add->($a, $b) } {}, keys %scores }; + +printf "$_ %s\n\n", join q( ), sort @{$inverse{$_}} for sort keys %inverse; diff --git a/challenge-081/juliodcs/perl/input b/challenge-081/juliodcs/perl/input new file mode 100644 index 0000000000..7c77fa54a9 --- /dev/null +++ b/challenge-081/juliodcs/perl/input @@ -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. \ No newline at end of file diff --git a/challenge-081/juliodcs/raku/ch-1.raku b/challenge-081/juliodcs/raku/ch-1.raku new file mode 100644 index 0000000000..6ee984714b --- /dev/null +++ b/challenge-081/juliodcs/raku/ch-1.raku @@ -0,0 +1,3 @@ +use v6.d; + +say @*ARGS.map({ /^ (.+) $0+ $/; $0 }).grep(so *).map(~*).unique; diff --git a/challenge-081/juliodcs/raku/ch-2.raku b/challenge-081/juliodcs/raku/ch-2.raku new file mode 100644 index 0000000000..c7e103f4ee --- /dev/null +++ b/challenge-081/juliodcs/raku/ch-2.raku @@ -0,0 +1,15 @@ +use v6.d; + +my $regex := rx/ :r # Don't backtrack + 「'」> # Don't match if preceded by word + 「'」 + # (avoids matching 「s」 in 「word's」) + <:L>+ [「-」<:L>+]* # Match dash-separated words + [「'」><:L>+]? # It may end with 「'」 + word (except for 「's」) +/; + +my @words := ('input'.IO.slurp ~~ m:g/$regex/)>>.Str; +my %score := ({}, |@words).reduce: { %^score{$^word}++; %^score } +my $add := { %^data{$^pair.value}.push: $^pair.key; %^data } +my %data := ({}, |%score.pairs).reduce: $add; + +printf "%s %s\n\n", .key, .value.sort.join: 「 」 for sort %data.pairs; diff --git a/challenge-081/juliodcs/raku/input b/challenge-081/juliodcs/raku/input new file mode 100644 index 0000000000..7c77fa54a9 --- /dev/null +++ b/challenge-081/juliodcs/raku/input @@ -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. \ No newline at end of file -- cgit