diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-10-11 19:32:34 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-10-11 19:32:34 +0100 |
| commit | 4c6073945132e3a55a4d0561b77219f01d335945 (patch) | |
| tree | 110111b15058fdf7b3b8e3fc8db1940a125dbcab | |
| parent | 248cfb41a97ac7ebfbd01d9ddded5eb44af7fb1c (diff) | |
| download | perlweeklychallenge-club-4c6073945132e3a55a4d0561b77219f01d335945.tar.gz perlweeklychallenge-club-4c6073945132e3a55a4d0561b77219f01d335945.tar.bz2 perlweeklychallenge-club-4c6073945132e3a55a4d0561b77219f01d335945.zip | |
- Added APL solutions by Richard Park.
| -rw-r--r-- | challenge-081/richard-park/apl/CommonBaseString.aplf | 11 | ||||
| -rw-r--r-- | challenge-081/richard-park/apl/FrequencySort.aplf | 7 | ||||
| -rw-r--r-- | challenge-081/richard-park/apl/WSS.txt | 3 | ||||
| -rw-r--r-- | challenge-081/richard-park/apl/ch-1.aplf | 11 | ||||
| -rw-r--r-- | challenge-081/richard-park/apl/ch-2.aplf | 7 |
5 files changed, 39 insertions, 0 deletions
diff --git a/challenge-081/richard-park/apl/CommonBaseString.aplf b/challenge-081/richard-park/apl/CommonBaseString.aplf new file mode 100644 index 0000000000..8bb924deb8 --- /dev/null +++ b/challenge-081/richard-park/apl/CommonBaseString.aplf @@ -0,0 +1,11 @@ + CommonBaseString←{ + FindBaseStrings←{ + ⍺←1 + ⍺=≢⍵:⍬ ⍝ Reached end of string + bs←⍺↑⍵ ⍝ Base String candidate + bs←⍺{(bs←⍺↑⍵)≡,↑∪⍵⊂⍨(⍺↑1)⍴⍨≢⍵:bs ⋄ ⍬}⍵ ⍝ Substring is a base string, else ⍬ + ⍬≡bs:(⍺+1)∇ ⍵ ⍝ If no base string, increment substring length and try again + (⊂⍬)~⍨bs,⍥⊆(2×⍺)∇ ⍵ ⍝ Return base string, and check superstrings (,⍨bs) + } + ⍺∪⍥FindBaseStrings ⍵ ⍝ Common base strings of ⍺ and ⍵ + } diff --git a/challenge-081/richard-park/apl/FrequencySort.aplf b/challenge-081/richard-park/apl/FrequencySort.aplf new file mode 100644 index 0000000000..52b9559f6e --- /dev/null +++ b/challenge-081/richard-park/apl/FrequencySort.aplf @@ -0,0 +1,7 @@ + r←FrequencySort fpath;key;text;words + (text encoding newline)←⊃⎕NGET fpath ⍝ Read text file + clean←('[."(),-]' '''s\b'⎕R'')text ⍝ No punctuation or 's + words←(' ',⎕UCS newline)((~∊⍨)⊆⊢)clean ⍝ Nested vec of char vec + (unique count)←{⍺(≢⍵}⌸words ⍝ Frequency count of words + bynumber←count{⍺(⊃(⊣,' ',⊢)/⍵[⍋⍵])}⌸unique ⍝ Group words by count (and sort within each grouping) + {(⊂⍋⍵)⌷⍵}bynumber ⍝ Sort by count
\ No newline at end of file diff --git a/challenge-081/richard-park/apl/WSS.txt b/challenge-081/richard-park/apl/WSS.txt new file mode 100644 index 0000000000..d2bb45d308 --- /dev/null +++ b/challenge-081/richard-park/apl/WSS.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.
\ No newline at end of file diff --git a/challenge-081/richard-park/apl/ch-1.aplf b/challenge-081/richard-park/apl/ch-1.aplf new file mode 100644 index 0000000000..8bb924deb8 --- /dev/null +++ b/challenge-081/richard-park/apl/ch-1.aplf @@ -0,0 +1,11 @@ + CommonBaseString←{ + FindBaseStrings←{ + ⍺←1 + ⍺=≢⍵:⍬ ⍝ Reached end of string + bs←⍺↑⍵ ⍝ Base String candidate + bs←⍺{(bs←⍺↑⍵)≡,↑∪⍵⊂⍨(⍺↑1)⍴⍨≢⍵:bs ⋄ ⍬}⍵ ⍝ Substring is a base string, else ⍬ + ⍬≡bs:(⍺+1)∇ ⍵ ⍝ If no base string, increment substring length and try again + (⊂⍬)~⍨bs,⍥⊆(2×⍺)∇ ⍵ ⍝ Return base string, and check superstrings (,⍨bs) + } + ⍺∪⍥FindBaseStrings ⍵ ⍝ Common base strings of ⍺ and ⍵ + } diff --git a/challenge-081/richard-park/apl/ch-2.aplf b/challenge-081/richard-park/apl/ch-2.aplf new file mode 100644 index 0000000000..52b9559f6e --- /dev/null +++ b/challenge-081/richard-park/apl/ch-2.aplf @@ -0,0 +1,7 @@ + r←FrequencySort fpath;key;text;words + (text encoding newline)←⊃⎕NGET fpath ⍝ Read text file + clean←('[."(),-]' '''s\b'⎕R'')text ⍝ No punctuation or 's + words←(' ',⎕UCS newline)((~∊⍨)⊆⊢)clean ⍝ Nested vec of char vec + (unique count)←{⍺(≢⍵}⌸words ⍝ Frequency count of words + bynumber←count{⍺(⊃(⊣,' ',⊢)/⍵[⍋⍵])}⌸unique ⍝ Group words by count (and sort within each grouping) + {(⊂⍋⍵)⌷⍵}bynumber ⍝ Sort by count
\ No newline at end of file |
