foo=: 4 : 0
'd c'=. x
z=. (c#i.#c) </. y
while. *#i=. I.0<d=. <:d do.
z=. (<"0 i{z) i}z
end.
)
Improvements to the above are left as an exercise
for the reader :-)
----- Original Message -----
From: "R.E. Boss" <[email protected]>
Date: Wednesday, June 3, 2009 11:52
Subject: [Jprogramming] leveled as indicated
To: 'Programming forum' <[email protected]>
> Looking for a dyadic foo
>
>
>
> with
>
> 4 = (3!:0)
> x NB. x is integer
>
> (# x) = 2 = #$ x NB. x has
> 2 items and has rank 2
>
> (# y) = +/{: x
>
> 0 < <./{.
> x NB. {.x
> is positive
>
>
>
> such that
>
>
>
> ({.x) -: L."0 x foo y NB.
> {.x is level of leaves
>
>
>
> ({:x) -: # S:0 x foo y NB. {:x is
> tally of leaves
>
>
>
>
>
> Example:
>
>
>
> (1 2 3 2 3 1,:2 1 3 2 1 3) foo i.12
>
> +---+---+---------+-----+-----+-------+
>
> |0 1|+-+|+-------+|+---+|+---+|9 10 11|
>
> | ||2|||+-----+|||6 7|||+-
> +|| |
>
> | |+-+|||3 4 5|||+---
> +|||8||| |
>
> | | ||+-----+||
> ||+-+|| |
>
> | | |+-------+|
> |+---+| |
>
> +---+---+---------+-----+-----+-------+
>
>
>
>
>
> R.E. Boss
>
> -----------------------------------------------------------------
> -----
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm