diff options
| author | Myoungjin JEON <jeongoon@gmail.com> | 2020-10-15 00:04:11 +1100 |
|---|---|---|
| committer | Myoungjin JEON <jeongoon@gmail.com> | 2020-10-15 00:04:11 +1100 |
| commit | dd71532a73981ec613c8c61d99fa4bbd3f3fd79c (patch) | |
| tree | 70b1b5c1613f51461bb27f6b4aa49ba8b5efa78e /challenge-081/richard-park/apl/ch-1.aplf | |
| parent | 99053d27c19ab6baee10484e8de730527333ddde (diff) | |
| parent | a86e289ff2bb02e7c579be9175c92f2667168a28 (diff) | |
| download | perlweeklychallenge-club-dd71532a73981ec613c8c61d99fa4bbd3f3fd79c.tar.gz perlweeklychallenge-club-dd71532a73981ec613c8c61d99fa4bbd3f3fd79c.tar.bz2 perlweeklychallenge-club-dd71532a73981ec613c8c61d99fa4bbd3f3fd79c.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-081/richard-park/apl/ch-1.aplf')
| -rw-r--r-- | challenge-081/richard-park/apl/ch-1.aplf | 11 |
1 files changed, 11 insertions, 0 deletions
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 ⍵ + } |
