diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-05-24 22:07:00 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-05-24 22:07:00 +0100 |
| commit | b09d14aaf6983cefc430926688787b4d46c537a7 (patch) | |
| tree | 9fd9ebbf093c5daa3e5f8ae2107cede3efb7d070 /challenge-061 | |
| parent | ed274477348aa4d5508b13ff0576c7f9f0e0ce3c (diff) | |
| download | perlweeklychallenge-club-b09d14aaf6983cefc430926688787b4d46c537a7.tar.gz perlweeklychallenge-club-b09d14aaf6983cefc430926688787b4d46c537a7.tar.bz2 perlweeklychallenge-club-b09d14aaf6983cefc430926688787b4d46c537a7.zip | |
- Added APL solutions by Richard Park.
Diffstat (limited to 'challenge-061')
| -rw-r--r-- | challenge-061/richard-park/apl/IPv4Partition.aplf | 13 | ||||
| -rw-r--r-- | challenge-061/richard-park/apl/ProductSubArray.aplf | 10 | ||||
| -rw-r--r-- | challenge-061/richard-park/apl/ch-1.aplf | 10 | ||||
| -rw-r--r-- | challenge-061/richard-park/apl/ch-2.aplf | 13 | ||||
| -rw-r--r-- | challenge-061/richard-park/blog.txt | 1 |
5 files changed, 47 insertions, 0 deletions
diff --git a/challenge-061/richard-park/apl/IPv4Partition.aplf b/challenge-061/richard-park/apl/IPv4Partition.aplf new file mode 100644 index 0000000000..c4d14b2f12 --- /dev/null +++ b/challenge-061/richard-park/apl/IPv4Partition.aplf @@ -0,0 +1,13 @@ + IPv4Partition←{ +⍝ Print every possible valid IPv4 address that can be made by partitioning the input string. +⍝ For the purpose of this challenge, a valid IPv4 address consists of four “octets” i.e. A, B, C and D, separated by dots (.). +⍝ Each octet must be between 0 and 255, and must not have any leading zeroes. (e.g., 0 is OK, but 01 is not.) + ⍺←4 + pvec←⍉2⊥⍣¯1⍳¯1+2*≢⍵ + parts←pvec{(1@1⊢⍺)⊂⍵}⍤1⊢⍵ + nparts←{0::'' ⋄ ⍕⍎⍵}¨parts + octets←nparts⌿⍨⍺=+/''∘≢¨nparts + inrange←{0::0 ⋄ n←⍎⍵ ⋄ (0≤n)∧(255≥n)}¨octets + validIPv4←octets⌿⍨⍺=+/inrange + ↑{⍺,'.',⍵}/⍤1∪⍺↑⍤1⊢validIPv4 + } diff --git a/challenge-061/richard-park/apl/ProductSubArray.aplf b/challenge-061/richard-park/apl/ProductSubArray.aplf new file mode 100644 index 0000000000..95456670c0 --- /dev/null +++ b/challenge-061/richard-park/apl/ProductSubArray.aplf @@ -0,0 +1,10 @@ + ProductSubArray←{ +⍝ Given a list of 4 or more numbers, write a script to find the contiguous sublist that has the maximum product. + array←⍵ + length←≢⍵ + 4>length:'⍵ must be a numeric list of length ≥ 4'⎕SIGNAL 11 + csa←↑array∘{{⊂⍵}⌺⍵⊢⍺}¨⍳length + products←×/¨csa + max←⌈/,products + ((,products)⍳max)⊃(,csa) + } diff --git a/challenge-061/richard-park/apl/ch-1.aplf b/challenge-061/richard-park/apl/ch-1.aplf new file mode 100644 index 0000000000..95456670c0 --- /dev/null +++ b/challenge-061/richard-park/apl/ch-1.aplf @@ -0,0 +1,10 @@ + ProductSubArray←{ +⍝ Given a list of 4 or more numbers, write a script to find the contiguous sublist that has the maximum product. + array←⍵ + length←≢⍵ + 4>length:'⍵ must be a numeric list of length ≥ 4'⎕SIGNAL 11 + csa←↑array∘{{⊂⍵}⌺⍵⊢⍺}¨⍳length + products←×/¨csa + max←⌈/,products + ((,products)⍳max)⊃(,csa) + } diff --git a/challenge-061/richard-park/apl/ch-2.aplf b/challenge-061/richard-park/apl/ch-2.aplf new file mode 100644 index 0000000000..c4d14b2f12 --- /dev/null +++ b/challenge-061/richard-park/apl/ch-2.aplf @@ -0,0 +1,13 @@ + IPv4Partition←{ +⍝ Print every possible valid IPv4 address that can be made by partitioning the input string. +⍝ For the purpose of this challenge, a valid IPv4 address consists of four “octets” i.e. A, B, C and D, separated by dots (.). +⍝ Each octet must be between 0 and 255, and must not have any leading zeroes. (e.g., 0 is OK, but 01 is not.) + ⍺←4 + pvec←⍉2⊥⍣¯1⍳¯1+2*≢⍵ + parts←pvec{(1@1⊢⍺)⊂⍵}⍤1⊢⍵ + nparts←{0::'' ⋄ ⍕⍎⍵}¨parts + octets←nparts⌿⍨⍺=+/''∘≢¨nparts + inrange←{0::0 ⋄ n←⍎⍵ ⋄ (0≤n)∧(255≥n)}¨octets + validIPv4←octets⌿⍨⍺=+/inrange + ↑{⍺,'.',⍵}/⍤1∪⍺↑⍤1⊢validIPv4 + } diff --git a/challenge-061/richard-park/blog.txt b/challenge-061/richard-park/blog.txt new file mode 100644 index 0000000000..c961389df5 --- /dev/null +++ b/challenge-061/richard-park/blog.txt @@ -0,0 +1 @@ +https://www.youtube.com/watch?v=UBl6t7zNfwE |
