aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-11 15:54:44 +0100
committerGitHub <noreply@github.com>2020-10-11 15:54:44 +0100
commita330b91f1e526c4bcb35533bc961690008d34661 (patch)
treeb77e06a275da85f120fbe6f357cc48a01f702d43
parenta21f55bc31e9694a366c75c5f4bd9c450dc6b788 (diff)
parent05f16e073363569819c1d09ec84a10477a9759b3 (diff)
downloadperlweeklychallenge-club-a330b91f1e526c4bcb35533bc961690008d34661.tar.gz
perlweeklychallenge-club-a330b91f1e526c4bcb35533bc961690008d34661.tar.bz2
perlweeklychallenge-club-a330b91f1e526c4bcb35533bc961690008d34661.zip
Merge pull request #2487 from wambash/challange-week-081
solutions week 081
-rw-r--r--challenge-081/wambash/raku/ch-1.raku26
-rw-r--r--challenge-081/wambash/raku/ch-2.raku40
-rw-r--r--challenge-081/wambash/raku/input.txt3
3 files changed, 69 insertions, 0 deletions
diff --git a/challenge-081/wambash/raku/ch-1.raku b/challenge-081/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..feb3020df9
--- /dev/null
+++ b/challenge-081/wambash/raku/ch-1.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+sub common-base-string ( $a, $b ) {
+ $a.match(/
+ ^ (.+) $0* $
+ <?{
+ with $0 {
+ $b.match: / ^ "$_"+ $ /
+ }
+ }>
+ /,
+ :ex
+ );
+ $/.map: *.[0].Str
+}
+
+multi MAIN ( $a, $b ) {
+ say common-base-string($a, $b);
+}
+
+multi MAIN ( :$test ) {
+ use Test;
+ is common-base-string( 'abcdabcd', 'abcdabcdabcdabcd' ), <abcdabcd abcd>;
+ is common-base-string( 'aaa', 'aa' ), < a >;
+ done-testing;
+}
diff --git a/challenge-081/wambash/raku/ch-2.raku b/challenge-081/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..1a2adc15ee
--- /dev/null
+++ b/challenge-081/wambash/raku/ch-2.raku
@@ -0,0 +1,40 @@
+#!/usr/bin/env raku
+
+sub detox (Str $a) {
+ $a
+ andthen .trans: '."(),' => ''
+ andthen .subst: / <[']> s ยป /, '', :g
+ andthen .subst: / '--' /, ' ',:g
+}
+
+multi frequency-sort ( IO(Any) :$input-file! ) {
+ $input-file
+ andthen .slurp
+ andthen samewith $_
+}
+
+multi frequency-sort ( Str $input ) {
+ $input
+ andthen .&detox
+ andthen .words
+ andthen .Bag
+ andthen .sort
+ andthen .classify: *.value, as => *.key
+}
+
+multi MAIN () {
+ put frequency-sort slurp() ;
+}
+
+multi MAIN ( IO(Str) $file ) {
+ put frequency-sort :input-file( $file );
+}
+
+multi MAIN ( Bool :$test! ) {
+ use Test;
+ my $fs = frequency-sort :input-file<input.txt> ;
+ is $fs.{9}, <and the>;
+ is $fs.{3}, <Maria Tony a can of stop>;
+ is $fs.{1}.elems, 84;
+ done-testing;
+}
diff --git a/challenge-081/wambash/raku/input.txt b/challenge-081/wambash/raku/input.txt
new file mode 100644
index 0000000000..37001629ad
--- /dev/null
+++ b/challenge-081/wambash/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.