bill lam wrote: 
> btw anyone knows how to do it in C or have a pointer?  May be this serves as 
> an 
> example of "C for J Programmers" :-) 
 
Here's a rough approximation, in J, of how it could be done in C:
 
zigzag=:3 :0
 lim=.*/'X Y'=.y
 'J K'=.y-1
 r=.,y$n=.j=.k=.0
 d=.1
 while.n<lim do.
  r=.n (k+Y*j)} r
  n=.n+1
  if.d>0 do.
   if.k<K do.
    k=.k+d
   else.
    d=._1
    j=.j+1
    continue.
   end.
   if.j do.
    j=.j-d
   else.
    d=._1
   end.
  else.
   if.j<J do.
    j=.j-d
   else.
    d=.1
    k=.k+1
    continue.
   end.
   if.k do.
    k=.k+d
   else.
    d=.1
   end.
  end.
 end.
 y$r
)
 
An advantage of this approach is that it's O(#r)
 
However, for example, if I had not included the variables J and K
and had used X and Y in their place, the code would be incorrect
and the reasons for that might have been difficult to determine.
 
FYI,
 
-- 
Raul
 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to