3 ms·
> tenK←'^........k.$' ⎕S '&' ⊢ words ⍝ regex filter Is tenK←{(10=≢⍵)∧⍵[9]='k'}¨words better? Feel that better matches the problem spec, although requires th
by bear8642 3y ago
> tenK←'^........k.$' ⎕S '&' ⊢ words ⍝ regex filter
Is tenK←{(10=≢⍵)∧⍵[9]='k'}¨words better?
Feel that better matches the problem spec, although requires the each
- jodrellblank 3y ago⍵[9] INDEX ERRORs on the shorter words, and that code needs a compress to do the filtering. It's a more traditional and faster approach, which is better from those viewpoints. If faster and avoiding each and using array concepts is desirable, how about: words←↑⊃⎕nget 'wordlist.txt' 1 tenK←words⌿⍨('k'=words[;9])∧(' '≠words[;10])∧(' '=words[;11]) tenK⌿⍨{∧/1='abc'(+/∘.∊)⍵}⍤1⊢tenK Mix ↑ turns the nested wordlist into a 2D array by padding short strings out to the length of the longest using spaces, which I don't like but am (ab)using here to tell when the words end.