Here's a slight improvement.
reroot=: 4 : 0
'p c'=. |:x
x |."0 1~ c e. (p {~ c&i.)^:(e.&c)^:a: y
)
>tree t1 reroot 3
+- 8
+- 9
+- 4 -+- 10
| +- 11
+- 1 --- 0 --- 2 -+ +- 12
| +- 5 -+- 13
| +- 14
| +- 15
- 3 -+- 6 -+- 16
| +- 17
| +- 18
+- 7 -+- 19
--- On Mon, 5/19/08, Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
> Looks like you just need to
> flip each pair in path from old root to new root
>
> |: t1 (|."[EMAIL PROTECTED])}~ c i. }: (p {~ c i. ])^:(c
> e.~])^:a: 3
> 1 0 3 2 2 3 3 4 4 4 4 5 5 6 6 6 6 7 7
> 0 2 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> tree t1 (|."[EMAIL PROTECTED])}~ c i. }: (p {~ c i. ])^:(c
> e.~])^:a: 3
> +----------------------------------+
> | +- 8 |
> | +- 9 |
> | +- 4 -+- 10|
> | | +- 11|
> | +- 1 --- 0 --- 2 -+ +- 12|
> | | +- 5 -+- 13|
> | | +- 14 |
> | | +- 15 |
> |- 3 -+- 6 -+- 16 |
> | | +- 17 |
> | | +- 18 |
> | +- 7 -+- 19 |
> +----------------------------------+
>
>
> --- On Mon, 5/19/08, Jose Mario Quintana
> <[EMAIL PROTECTED]> wrote:
>
> > From: Jose Mario Quintana
> <[EMAIL PROTECTED]>
> > Subject: Re: [Jprogramming] Displaying trees - J
> Wiki/Essays/Tree Sum
> > To: "Programming forum"
> <[email protected]>
> > Date: Monday, May 19, 2008, 12:12 PM
> > A directed tree can be rerooted at any of its nodes.
> For
> > example, t1 from
> > http://www.jsoftware.com/jwiki/Essays/Tree_Display ,
> >
> >
> > |:t1
> > 0 0 1 2 2 3 3 4 4 4 4 5 5 6 6 6 6 7 7
> > 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> > tree t1
> > +----------------------------+
> > | ┌─ 14|
> > | ├─ 15|
> > | ┌─ 6 ─┼─ 16|
> > | │ └─ 17|
> > | ┌─ 1 ─── 3 ─┤ ┌─ 18|
> > | │ └─ 7 ─┴─ 19|
> > | │ ┌─ 8 |
> > |─ 0 ─┤ ├─ 9 |
> > | │ ┌─ 4 ─┼─ 10 |
> > | │ │ └─ 11 |
> > | └─ 2 ─┤ ┌─ 12 |
> > | └─ 5 ─┴─ 13 |
> > +----------------------------+
> >
> > Can be rerooted at 3 as,
> >
> > tree t2=. 3 reroot t1
> > +----------------------------------+
> > | ┌─ 14 |
> > | ├─ 15 |
> > | ┌─ 6 ─┼─ 16 |
> > | │ └─ 17 |
> > | │ ┌─ 18 |
> > | ├─ 7 ─┴─ 19 |
> > |─ 3 ─┤ ┌─ 8 |
> > | │ ├─ 9 |
> > | │ ┌─ 4 ─┼─ 10|
> > | │ │ └─ 11|
> > | └─ 1 ─── 0 ─── 2 ─┤
> ┌─ 12|
> > | └─ 5 ─┴─ 13|
> > +----------------------------------+
> >
> > |:t2 NB. (reroot rendering t2 or equivalent)
> > 3 3 6 6 6 6 7 7 3 1 0 2 2 4 4 4 4 5 5
> > 6 7 14 15 16 17 18 19 1 0 2 4 5 8 9 10 11 12 13
> >
> >
> > Has any J version of reroot been made public already?
> >
> >
> > ----- Original Message ----
> > From: Roger Hui <[EMAIL PROTECTED]>
> >
> > Nothing new under the sun.
> >
> http://groups.google.com/group/comp.lang.apl/browse_thread/thread/5f1c1df7bd72fe51/32691205433c3152?lnk=gst#32691205433c3152
> >
> > ----- Original Message -----
> > From: Roger Hui <[EMAIL PROTECTED]>
> >
> > >
> http://www.jsoftware.com/jwiki/Essays/Tree_Display
> > >
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm