aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio <julio.dcs@gmail.com>2020-10-06 17:44:56 +0200
committerJulio <julio.dcs@gmail.com>2020-10-06 17:44:56 +0200
commit2a7f54ab092f795e9e88613f6e48b4d794a8c99d (patch)
treeea5e908c19416f8210efeeebdb2e0b08d1eed5fb
parentcef248ba491398a30061ba49fbc2a824116ae996 (diff)
downloadperlweeklychallenge-club-2a7f54ab092f795e9e88613f6e48b4d794a8c99d.tar.gz
perlweeklychallenge-club-2a7f54ab092f795e9e88613f6e48b4d794a8c99d.tar.bz2
perlweeklychallenge-club-2a7f54ab092f795e9e88613f6e48b4d794a8c99d.zip
Add solution for week 81
-rw-r--r--challenge-081/juliodcs/perl/ch-1.pl6
-rw-r--r--challenge-081/juliodcs/perl/ch-2.pl19
-rw-r--r--challenge-081/juliodcs/perl/input3
-rw-r--r--challenge-081/juliodcs/raku/ch-1.raku3
-rw-r--r--challenge-081/juliodcs/raku/ch-2.raku15
-rw-r--r--challenge-081/juliodcs/raku/input3
6 files changed, 49 insertions, 0 deletions
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}') # Don't match if preceded by word + 「'」
+ # (avoids matching 「s」 in 「word's」)
+ \p{L}++ (?>-\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
+ <!after <:L>「'」> # Don't match if preceded by word + 「'」
+ # (avoids matching 「s」 in 「word's」)
+ <:L>+ [「-」<:L>+]* # Match dash-separated words
+ [「'」<!before 「s」<ws>><: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