Let me take this opportunity to mention a fine point, which has nothing to do with this particular program.

Sentences whose result might become the overall result are followed by an extra step as that result is saved for possible return. Saving the result is essentially free UNLESS it is an array with a lot of boxes, in which case the cost of protecting each box can be noticeable.

In this program, the assignments to m are possibly results. If m were a large boxed array, the program would run faster if an additional lineto give the return valuewere added after the loop, reading:

m

Henry Rich


On 6/25/2017 10:14 AM, Raul Miller wrote:
I don't think a tacit version can be this fast and still be as readable.

That said, it is possible to delete a line from this implementation.
Sadly, that was the fastest line, so no speedup:

cs1=: 3 : 0
   m=. >./y
   for_i. }.>:i.n=. #y do.
     m=. m>.q=. i*>./y=. 2<./\y
     if. (m*i)>:n*q do. break. end.
   end.
)

(Also, for tutorial value - the break. can be replaced with return. as
they are equivalent in this context. Put differently: the value
returned by an explicit verb is that of the last non-test statement
which was executed.)

Thanks,



---
This email has been checked for viruses by AVG.
http://www.avg.com

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to