aboutsummaryrefslogtreecommitdiff
path: root/challenge-081/richard-park/apl/CommonBaseString.aplf
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-081/richard-park/apl/CommonBaseString.aplf')
-rw-r--r--challenge-081/richard-park/apl/CommonBaseString.aplf11
1 files changed, 11 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 ⍵
+ }