Roger Hui wrote:
>
>> Thanks for the link. I've checked out the code there, lots of
>> very interesting solutions, but haven't found any one
>> similar to '(,[EMAIL PROTECTED])^:34(1 0)'
>
> The expression (,[EMAIL PROTECTED])^:34(1 0) is very similar to f2a in
> http://www.jsoftware.com/jwiki/Essays/Fibonacci_Sequence#iteration
>
Then we can call it f2a1 .
f2a=: 3 : '{. +/\@|.^:y 0 1x'
NB. similarity/difference:
NB. tacit f2a: [: {. +/\@|. ^: ( ] `(0 1x"_))
f2a1=: [: {. ({.,~{.+{:) ^: (<:`(1 0x"_))
NB. one faster and shorter routine is:
f6a=: i. +/ .! [EMAIL PROTECTED]
ts=:'6!:2,(7!:2)@]'
NB. Performance improvement:
1000 ts 'f2a 100'
0.0009664440592 3840
1000 ts 'f2a1 100'
0.0004908833385 1728
1000 ts 'f6a 100'
7.818116548e_5 5888
1000 ts 'f2a 1000'
0.008351288502 4800
1000 ts 'f2a1 1000'
0.003922655254 2688
1000 ts 'f6a 1000'
0.001268231577 38144
--
View this message in context:
http://www.nabble.com/Performance-comparison-tp14595315s24193p14603028.html
Sent from the J General mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm