On Fri, Aug 7, 2020 at 6:28 PM 'Pascal Jasmin' via Programming
wrote:
> That said, it would be neat if we could trick (5!:4) into pretty-printing (s)
> for us.
5!:4 will not represent 4 children.
--
Raul
--
For information abou
applyintree =: 2 : 0
i =. >^:((1=#)@>) {. n
(u`(u applyintree (}.n))@.(1<#n)&.:> i{y) i} y
:
i =. >^:((1=#)@>) {. n
((x&u)`(x&(u applyintree (}.n)))@.(1<#n)&.:> i{y) i} y
)
NB. where depth vector is sorted nodes by parent/child relationship. No skipped
depths or boxing levels.
NB. use {
Alternative (slightly more compact) implementation of tv:
tv=: (0 = {.) *./@, (0 < {:), 1 >: +/\inv
Meanwhile, this is probably a bit long (almost 100 characters) to be
called a one line implementation, but it seems to be in the right
ballpark:
;"1(' - ',&.>' o+|'){~(+3*_1 1&E.)"1&.|:(*
>
O, I just wanted to write a follow-up to my cloumsy attempts
but this one is obviously way better.
Still, it depends on what you want to be able to see at first glance
and how much of your 'terseness requirement' you are willing
to sacrifice for it.
Am 07.08.20 um 18:44 schrieb x...@xn--wxa.land
For your original format, with a transition matrix to simplify finding
"catenaries" for each column:
tm=:3 4 $ 0 1 0 1 2 2 2 2 3 1 3 1
start=: 0,~ = + 2*(=>:) NB. same height = 1, direct children = 2, others = 0
step=: {::&tm@, NB. apply tm
nub=: ] ,:~ 4* 2= ] NB. '-'
If the mountain graph suits you well, how about
,./ ((i.@#) ((' ' , ":@[) {~ =)"0 1 ]) d
0
1
2
2
1
1
2
2
3
?
Am 07.08.20 um 18:12 schrieb ethiejiesa via Programming:
Thanks for the thoughts!
not as pretty, but simpler and pretty enough?
(":"0@i.@# (,~ #&'-')"1 0 ]) 0 1 2
Thanks for the thoughts!
> not as pretty, but simpler and pretty enough?
>
> (":"0@i.@# (,~ #&'-')"1 0 ]) 0 1 2 2 1 1 2 2 3
>
> 0
>
> -1
>
> --2
>
> --3
>
> -4
>
> -5
>
> --6
>
> --7
>
> ---8
This is sort of in between the raw depth vector and the graph representation.
It's probably f
You could build a oneliner out of this multistage process:
d =: 0 1 2 2 1 1 2 2 3
indent =: ' ' <@(#"0 1~) 0 >. <: +/ (i.@# /)"1 indent,.branch
prefix =: '| ' <@#"0 1~ d - , -:@$@> infix
;"1 prefix ,. infix ,. <'o'
which gives the desired result for d
I didn’t test on larger/more
not as pretty, but simpler and pretty enough?
(":"0@i.@# (,~ #&'-')"1 0 ]) 0 1 2 2 1 1 2 2 3
0
-1
--2
--3
-4
-5
--6
--7
---8
J has several functions built in to process trees that are represented as
nested box structures, and so may be useful in converting from various
representatio
Do you know a slick way of pretty-printing a tree given its depth vector
representation?
A vector represents a tree if and only if it satisfies the following:
NB. Tree valid? First node is root node (depth 0), only one root node,
NB. and all nodes are exactly one deeper than their p
On 8/7/20, Raul Miller wrote:
>row=.1
>col=.2
>row,col
> 1 2
>row col
> |syntax error
THAT was the cherry on top of the sundae! My program now works
exactly as it is supposed to!
Thank you VERY much, Pascal, Bob, Ric, and Raul!! You all are the
greatest J helpers!
Harvey
-
11 matches
Mail list logo