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,27 @@
# Input: an array representing a tree
# Output: a stream of strings representing the tree
# In this implementation, empty arrays in the tree are simply ignored.
def printTree:
def tidy:
sub("└─$"; " ")
| sub("├─$"; "| ") ;
# Input: a string prefix
def print($tree):
if $tree|type != "array" then . + ($tree|tostring)
else # ignore empty arrays
($tree | map(select(if type == "array" then length>0 else true end))) as $tree
| if $tree|length == 0 then empty
elif $tree|length == 1
then print($tree[0])
else print($tree[0]),
($tree[1:] as $children
| tidy as $p
| ($p + ( "├─" | print($children[:-1][]))),
($p + ( "└─" | print($children[-1]))) )
end
end ;
. as $tree
| "" | print($tree) ;

View file

@ -0,0 +1,21 @@
def bigTree:
["a",
["aa",
["aaa",
["aaaa"],
["aaab",
["aaaba"],
["aaabb"]],
["aaac"]]],
["ab"],
["ac",
["aca"],
["acb"],
["acc"]]] ;
[0, 1, 2, 3],
[1,[2,3,[4, 5, [6,7,8], 9, [10,11]]]],
bigTree
| ("Tree with array representation:\n\(.)\n",
printTree,
"")