Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,43 @@
BOXC=: 9!:6 '' NB. box drawing characters
EW =: {: BOXC NB. east-west
showtree=: 4 : 0
NB. y is parent index for each node (non-indices for root nodes)
NB. x is label for each node
t=. (<EW,' ') ,@<@,:@,&":&.> x NB. tree fragments
c=. |:(#~ e./@|:);(~.,"0&.>(</. i.@#)) y
while. +./ b=. ({.c)*.//.-.e.~/c do.
i=. b#~.{.c NB. parents whose children are leaves
j=. </./(({.c)e.i)#"1 c NB. leaves grouped by parents
t=. a: (;j)}t i}~ (i{t) subtree&.> j{&.><t
c=. (-.({.c)e.i)#"1 c NB. prune edges to leaves
end.
;([: ,.&.>/ extend&.>)&> t -. a:
)
subtree=: 4 : 0
p=. EW={."1 s=. >{.t=. graft y
(<(>{.x) root p),(<(connect p),.s),}.t
)
graft=: 3 : 0
n=. (-~ >./) #&> y
f=. i.@(,&0)@#&.>@{.&.> y
,&.>/ y ,&> n$&.>f
)
connect=: 3 : 0
b=. (+./\ *. +./\.) y
c=. (b+2*y){' ',9 3 3{BOXC NB. │ NS ├ E
c=. (0{BOXC) (b i. 1)}c NB. ┌ NW
c=. (6{BOXC) (b i: 1)}c NB. └ SW
j=. (b i. 1)+<.-:+/b
EW&(j})^:(1=+/b) c j}~ ((0 3 6 9{BOXC)i.j{c){1 4 7 5{BOXC
)
root=: 4 : 0
j=. k+<.-:1+(y i: 1)-k=. y i. 1
(-j)|.(#y){.x,.,:' ',EW
)
extend=: 3 : '(+./\"1 (y=EW) *. *./\."1 y e.'' '',EW)}y,:EW'

View file

@ -0,0 +1,6 @@
(i.10) showtree _,}.p:inv i.10
┌─ 6
┌─ 1 ─── 3 ─┴─ 7
│ ┌─ 8
─ 0 ─┤ ┌─ 4 ─┴─ 9
└─ 2 ─┴─ 5

View file

@ -0,0 +1,3 @@
(i.10),: _,}.p:inv i.10
0 1 2 3 4 5 6 7 8 9
_ 0 0 1 2 2 3 3 4 4

View file

@ -0,0 +1,6 @@
((<'george') 0} (<'fred') 4} ":each i.10)showtree _,}.p:inv i.10
┌─ 6
┌─ 1 ─── 3 ────┴─ 7
│ ┌─ 8
─ george ─┤ ┌─ fred ─┴─ 9
└─ 2 ─┴─ 5