Thanks for such a detailed answer! I'll read it carefully.
It's still hard for me to develop array programming reflexes
and even harder to optimize code in J.

In the meantime, I turn the math bit on and found another way
to compute the answer, avoiding brute force. It should even be
possible to find a direct formula but I didn't take the time.

Here is what I suggest:

peri =: 57
zmin =: 1 + >. peri % 3                NB. z + (z-1) + (z-2) >: peri
z =: zmin + i.( <.1 - zmin - peri % 2) NB. z < peri % 2
+/ (<. 1.5 * z) - >. 0.5 + peri %2     NB. (y+(y-1)>:peri-z)*.(y<z)

I'm sure there is a much shorter way to code this in J,
even if it won't probably change a lot computing time.
Could you show me the way to a one-liner?

Thanks in advance,

Olivier

> On 05/24/2013 10:36 PM, Raul Miller wrote:

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

Reply via email to