Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
27
Task/Visualize-a-tree/Jq/visualize-a-tree-1.jq
Normal file
27
Task/Visualize-a-tree/Jq/visualize-a-tree-1.jq
Normal 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) ;
|
||||
21
Task/Visualize-a-tree/Jq/visualize-a-tree-2.jq
Normal file
21
Task/Visualize-a-tree/Jq/visualize-a-tree-2.jq
Normal 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,
|
||||
"")
|
||||
Loading…
Add table
Add a link
Reference in a new issue