Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
40
Task/Visualize-a-tree/Phix/visualize-a-tree-1.phix
Normal file
40
Task/Visualize-a-tree/Phix/visualize-a-tree-1.phix
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
function rand_tree(integer low, integer high)
|
||||
for i=1 to 2 do
|
||||
integer v = rand(high-low+1)-1+low
|
||||
if v!=low
|
||||
and v!=high then
|
||||
return {v,rand_tree(low,v),rand_tree(v,high)}
|
||||
end if
|
||||
end for
|
||||
return 0
|
||||
end function
|
||||
|
||||
object tree = rand_tree(0,20) -- (can be 0, ~1% chance)
|
||||
|
||||
constant Horizontal = #C4,
|
||||
Horizontals = "\#C4",
|
||||
TopLeft = #DA,
|
||||
Vertical = #B3,
|
||||
BtmLeft = #C0
|
||||
|
||||
procedure visualise_tree(object tree, string root=Horizontals)
|
||||
if atom(tree) then
|
||||
puts(1,"<empty>\n")
|
||||
else
|
||||
object {v,l,r} = tree
|
||||
integer g = root[$]
|
||||
if sequence(l) then
|
||||
root[$] = iff(g=TopLeft or g=Horizontal?' ':Vertical)
|
||||
visualise_tree(l,root&TopLeft)
|
||||
end if
|
||||
root[$] = g
|
||||
puts(1,root)
|
||||
?v
|
||||
if sequence(r) then
|
||||
root[$] = iff(g=TopLeft?Vertical:' ')
|
||||
visualise_tree(r,root&BtmLeft)
|
||||
end if
|
||||
end if
|
||||
end procedure
|
||||
|
||||
visualise_tree(tree)
|
||||
1
Task/Visualize-a-tree/Phix/visualize-a-tree-2.phix
Normal file
1
Task/Visualize-a-tree/Phix/visualize-a-tree-2.phix
Normal file
|
|
@ -0,0 +1 @@
|
|||
pp(tree,{pp_Nest,10})
|
||||
Loading…
Add table
Add a link
Reference in a new issue