2 ms·
words←⊃⎕nget 'wordlist.txt' 1 ⍝ read lines tenK←'^........k.$' ⎕S '&' ⊢ words ⍝ regex filter ↑tenK/⍨{∧/1='abc'(+/∘.∊)⍵}¨tenK ⍝ count abc a
by jodrellblank 3y ago
words←⊃⎕nget 'wordlist.txt' 1 ⍝ read lines
tenK←'^........k.$' ⎕S '&' ⊢ words ⍝ regex filter
↑tenK/⍨{∧/1='abc'(+/∘.∊)⍵}¨tenK ⍝ count abc and filter
Dyalog APL, but it's still kinda ... heavy.
- 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.