[Jprogramming] k programming challenge
Dan Bron
j at bron.us
Thu Feb 4 20:04:33 UTC 2016
Linda wrote:
> words3=: 13 : ';:'' ''(([: I. tolower = toupper) y)}tolower y'
Please note:
words3=: 13 : ';:'' ''(([: I. tolower = toupper) y)}tolower y’
words3
3 : ';:'' ''(([: I. tolower = toupper) y)}tolower y'
That is, 13 : is incapable of converting the verb, as you have expressed it, to tacit form. Therefore the 13 : itself is superfluous, and it would be more direct and straightforward to simply define words3 using 3 : (not 13 : ) in the first place:
words3E =: 3 : ';:'' ''(([: I. tolower = toupper) y)}tolower y’
-:/ 5!:1 ;: 'words3 words3E’ NB. Identical representations
1
And, since we’re simply and directly defining an explicit verb, we might as well take advantage of all the other features explicit definitions offer us:
words3Elp =: verb define
lowerY =. tolower y
nonLettersIdx =. I. (toupper y) = lowerY
;: ' ' nonLettersIdx } lowerY
)
Clear, readable, and only a single calculation of tolower y . Of course, it has none of the advantages of Raul’s original formulation, but that loss happened when you “eliminate[d] At, Atop, Gerund and Rank”.
So, since that's a sunk cost, we might as well run with it, and get as much back for it as we can. Hope that’s what’s you meant when you said “maybe you can simplify it”.
-Dan
More information about the Programming
mailing list