On Thu, Aug 4, 2011 at 2:53 PM, [email protected] <[email protected]> wrote:
> Let's think of a family, only men, with fathers, children, grandchildren,
> grandfathers and so on. Each father can have several kids, but a kid can only
> have one father. Each one of the members of this family has numeric mark
> which he passes on to all his kids, so that the kids have their own number
> plus that of their father.
If that is a statement of the problem, then wouldn't a logical data
structure representing the relationship be, for each family member,
the index of their parent?
In other words:
I=: >./@I.(>/~i.#A)*.(=/ >:)A NB. parent indices
T=: (~.@,&.> ;@:{L:0 1~)^:_ I>.0 NB. transitive closure
R=: (i.#B) ~.@,L:0"0 T NB. reflexive closure
+/@:{&B&> R NB. sum
14 30 22 28 33 36 34 50 50 69 35 34 37 38 46 49 66 49 43 48 65 72 52
Ok, that looks like the data he asked for.
I expect that this particular formulation could be simplified somewhat
by using a bit representation of connections all the way through.
But I think A is an awkward representation of the relationship.
Also, this makes me wish for K's \
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm