here is my approach to fannkuch from nsl:
/ fannkuch
k)p:{1+$[0N!1<x;,/(>:'(x,x)#1,x#0)[;0,'1+p x-1];,!x]}
k)f:{G::0;{G+:1;@[x;i;:;|x i:!*x]}/x;F|:G-1}
q)p:{$[1<x;raze(idesc each (x,x)#1,x#0)[;0,/:1+p x-1];enlist til x]}
q)f:{-1+count {@[x;i;:;reverse x i:til first x]}scan x}
q)\t max f each 1+p 7
I replaced / for scan and removed globals setting.
what rule does it follow? How does it apply ‘reverse’ to only n elements specified by ‘first x’?
if that’s the vector ternary, i think it’s taking x as a list of flags in the first argument, and where they are “true” (non-zero), replacing that address with first x; where false, replacing it with the symmetrically equivalent element from the other end of the list. note that an atom in the second or third argument will be vector extended to match the other argument.