On Nov 25, 2006, at 7:34 AM, Oleg Kobchenko wrote:

I found a problem that is said to an assignment for introductory C course but it turned to be not so trivial. It can be rephrased in J as: for a positive integer m find the array v or equivalently (m,m)$v so that result is a matrix with atoms of i.*:m filling in zig-zag order. (restricted to square matrix for time being)

example
   4 4$0 1 5 6 2 4 7 12 3 8 11 13 9 10 14 15
0  1  5  6
2  4  7 12
3  8 11 13
9 10 14 15

I tackled the problem by noticing the sum of cell index pair for each layer is constant but run into trouble when need to eliminate extra pairs after passing
the middle layer.

All suggestions welcome.

PS. zig-zag order is used in jpeg encoding http://en.wikipedia.org/ wiki/JPEG
--

IN APL V Fifth International APL Users' Conference May 15-18, 1973, Toronto, is my paper "The Variety of Definitions of a Simple Function", giving 17 ways to solve this problem, not limiting it to square solutions. It discusses algebraic solutions and structural solutions. The solvers, besides myself, are Phil Abrams, Larry Breed, Graham Driscoll, Adin Falkoff, Michael Halpern, Ken Iverson, Howard Smith, Lou Solheim, Roy Sykes and S. Tsao. The solutions are not zigzag, however, but zigzag can be obtained by judicious use of reverse. It was written while the APL group was in Philadelphia, and where I was next to Ken when he stopped and calmed a runaway horse and held it until it was claimed.

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

Reply via email to