The format of A came up in a more extended problem I was working on. I did realize it represents a tree and know how to transfer it to other representations, but I wanted a solution from the format at hand. Then I was not very happy with the one I found, so that was reason to ask it to the forum (and I could practice my ability of writing specifications in plain text). Which brought me Lanzavecchia's algorithm.
R.E. Boss > -----Oorspronkelijk bericht----- > Van: [email protected] [mailto:programming- > [email protected]] Namens Raul Miller > Verzonden: donderdag 4 augustus 2011 21:38 > Aan: Programming forum > Onderwerp: Re: [Jprogramming] complicated sums of subarrays > > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
