Henry wrote:
Kicking the ball on down the field,
rmcol1 =: #~ _1 |. ~:&LF
I was going for a touchdown:
q =. LF
rmcol1 =: #~ _1 |. ~:&q
t =. =&q
s =. 2 1 1 1 0 2 1 2 2 2 1 2
fsm =. 1 ; (_2 ]\^:2 s) ; t a.
ijrd =. 1 , 0 , 1 ,~ t f.@:{.
FSM =. ;:~ fsm (,<) ijrd
rmcol2 =: FSM^:(1 < #) f.
but it turns out, in this case, mark-and-filter is faster than FSM!
Can anyone tell me why?
Well, for one thing, I don't think rmcol1 is "correct", so my
rmcol2 is NOT equivalent. A mark-and-filter solution equivalent to
rmcol2 would be:
rmcol3 =: (#~ [: -. (0 1 E. t)&.|.)&.(q&,) f.
which differs when y contains consecutive newlines, and when y
does not start with a newline.
But still; rmcol2 only scans the input once, whereas rmcol1 scans
it 3 times. Why is rmcol1 faster?
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm