More relevant than 

>    parents ,n ,: n treesum parents
>   0   0   1   2   2 3  3  4  4  4
>  46  25 101  69 102 9 58 45 40 64
> 559 513 488 136 251 9 58 45 40 64

seems to me

   (i.#n) ,n ,: n treesum parents
  0   1   2   3   4 5  6  7  8  9
 46  25 101  69 102 9 58 45 40 64
559 513 488 136 251 9 58 45 40 64


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens Raul Miller
> Verzonden: dinsdag 11 maart 2008 20:55
> Aan: Programming forum
> Onderwerp: [Jprogramming] tree sum and difference
> 
> So, let's say that I have a tree structure where 0
> is the parent of all other nodes
>    parents=: p:inv 1+i.10
> and that I have some numbers associated with
> the nodes of this tree
>    n=: ?.100+i.10
> 
> I can produce a tree-wise sum, for example:
>    connmat=:3 :'(e."0 1/ [:|:{&y^:a:)i.#y'
>    treesum=: +/ .* |:@connmat
>    parents,n,:n treesum parents
>   0   0   1   2   2 3  3  4  4  4
>  46  25 101  69 102 9 58 45 40 64
> 559 513 488 136 251 9 58 45 40 64
> 
> I can also find the tree-wise difference, for example:
>    treediff=: %. connmat
>    559 513 488 136 251 9 58 45 40 64 treediff parents
> 46 25 101 69 102 9 58 45 40 64
> 
> However, it seems that there ought to be faster
> approaches for large trees (with hundreds or
> thousands of nodes).
> 
> So, since some people like puzzles, can anyone
> come up with faster implementations for treesum
> and treediff, for large trees?
> 
> Thanks,
> 
> --
> 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

Reply via email to