Sorry about the frequent posts, but I remember
removing a test that did not mean anything from
an early version of this code. And, I think that
maxLevel was introduced to compensate for
how that test was not working. Which means that
it is not really needed. Which means that we could
instead do:
byLevel=: 4 :0
mask=. -. +./\ =i.{:$y
reflect=. 0&< * ] -"1"1 2 x *"2 1 ]
keep=. (0 < ^&mask"2) >&(*./"1) =&0
weights=. currentLevel=.,:y
while.#currentLevel do.
currentLevel=. (keep #&(,/) ]) reflect currentLevel
weights=. weights, currentLevel
end.
)
Example use:
A =: 4 4 $ 2 _1 0 0 _1 2 _1 0 0 _1 2 _1 0 0 _1 2
A byLevel 1 1 1 1
That said, I should probably have given this version
a new name, to emphasize the change in how it
is used.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm