Michal >i had a bit of a KB snafu ... actually timing results pegs cg about 20% faster >than collatz. The reason may well be obvious to an old time graphics >programmer (such as myself:) ... (>:++:) has 3 easy operations: an increment, >a double, and an add. Which are fast even on old 16b fixed point graphics >hardware! Whereas (>:@(3&*)) though it only has 2 ops has a real >multiplication in there (3&*). Plus i think the fork is kinda cooler:) but >thats just personal esthetics.
>cnv has its own memoization built right in w/o using M., results are stored >right in C. It is worth studying more, for me anyway. greg ~krsnadas.org -- from: Michal D. <[email protected]> to: [email protected] date: 5 August 2014 19:01 subject: Re: [Jprogramming] Memoizing (Project Euler problem 14) Oops, sorry for the premature post. --- >Thanks for the prod Greg, I understand *`* now, at least somewhat :-) >I think I would prefer the below which avoids factoring the multiplication as >(x+1)+(2*x), although that's a pretty cute trick. *1+3*]* has the advantage >of having only two operations (one +, one *) instead of three (two +, one *). *cgv=: 13 : '(2|y)} (<.-:)`(1+3*])`:0 y'* >Roger's version wins by a long shot (2.2 vs 2.1 vs 1.7). It invokes fewer >verbs. The interesting thing is that it's collatzv that runs faster not the >code that follows - meaning that the interpreter is smart enough to use >integer arithmetic before we even get to *<.* ?!? Cheers, Mike ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
