> But still; rmcol2 only scans the input once,
> whereas rmcol1 scans it 3 times. Why is
> rmcol1 faster?
a. Operations that you think should be O(n) are
not necessarily so. For example:
3 : '6!:2 '',~/t'' [ t=. y [EMAIL PROTECTED] 2'"0 ]1e4*1 2 4 8 16
0.0198894 0.0586494 0.186278 1.93452 6.88104
b. You are implying that one O(f) operation should
take about the same time as another O(f) operation.
This is not correct. For example, all of the
operations below are O(n), but:
t=: 1e6 [EMAIL PROTECTED] 2
6!:2 '+/t'
0.000690032
6!:2 '-/t'
0.0016382
6!:2 '|.t'
0.00257882
6!:2 '+:t'
0.0327461
6!:2 't{0 2'
0.00877067
----- Original Message -----
From: Dan Bron <[EMAIL PROTECTED]>
Date: Wed Dec 20 04:57:56 HKT 2006
Subject: Re: [Jprogramming] 0 : 0 including right paren?
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