Code: Select all
txt1←12345⍴,¨'this' 'is' 'a' 'sentence' ⍝ all vectors
txt2←12345⍴ 'this' 'is' 'a' 'sentence' ⍝ a scalar in the middle
cmpx '↑txt1' '↑txt2'
↑txt1 → 1.2E¯4 | 0% ⎕⎕
↑txt2 → 1.9E¯3 | +1508% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕...
And so:
Code: Select all
5↑txt←12345⍴,¨'this' 'is' 'a' 'sentence'
this is a sentence this
cmpx '⊃,/'' '',¨txt' '∊'' '',¨txt' '{n←1+≢¨⍵ ⋄ (,n∘.≥⍳⌈/n)/,'' '',↑⍵}txt'
⊃,/' ',¨txt → 2.5E¯3 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
∊' ',¨txt → 2.9E¯3 | +12% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
{n←1+≢¨⍵ ⋄ (,n∘.≥⍳⌈/n)/,' ',↑⍵}txt → 5.8E¯4 | -78% ⎕⎕⎕⎕
Vintage algorithms rock! (in this case, probably not after Roger discovers what is going on)...