a quick and dirt version of onion for rank-2 array, (beware of wrapping)
onion=: 1 : 0
'a b'=. $y
if. 0=a*.b do. '' return. end.
(u (<"1 ~.(0,.i.b),((i.a),.<:b),((<:a),.i.-b),((i.-a),.0)){y), u onion
}:@:(}:"1)@:}.@:(}."1) y
)
s=: $ /:@;@(<onion)@i.
s 4 5
0 1 2 3 4
13 14 15 16 5
12 19 18 17 6
11 10 9 8 7
bill lam wrote:
> By imitating the idiom
> z=: $ /:@;@(<@|.`</.)@i.
>
> the solution is trivial
> s=: $ /:@;@(<onion)@i.
>
> where onion is the adverb to partition an array in onion manner. adverb onion
> will be implemented by someone else. (oo paradigm)
>
> Roger Hui wrote:
>> Now that we have mastered zigzag order, how about the
>> spiral order? For example, the spiral order for a
>> 4 5 array is:
>>
>> 0 1 2 3 4
>> 13 14 15 16 5
>> 12 19 18 17 6
>> 11 10 9 8 7
>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
>
>
--
regards,
bill
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm