forked from adam-mcdaniel/program-evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_example.py
More file actions
35 lines (29 loc) · 842 Bytes
/
tree_example.py
File metadata and controls
35 lines (29 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from PrettyPrint import PrettyPrintTree
class Tree:
def __init__(self, value):
self.val = value
self.children = []
def add_child(self, child):
self.children.append(child)
return child
pt = PrettyPrintTree(lambda x: x.children, lambda x: x.val)
tree = Tree("")
child1 = tree.add_child(Tree(""))
child2 = tree.add_child(Tree("K"))
child1.add_child(Tree("I"))
child1.add_child(Tree("S"))
pt(tree)
print("\n")
pt2 = PrettyPrintTree(lambda x: x.children, lambda x: x.val)
tree2 = Tree("/\\")
I = tree2.add_child(Tree("I"))
one = tree2.add_child(Tree("/\\"))
two = one.add_child(Tree("/\\"))
three = one.add_child(Tree("/\\"))
three.add_child(Tree("S"))
three.add_child(Tree("K"))
two.add_child(Tree("S"))
four = two.add_child(Tree("/\\"))
four.add_child(Tree("K"))
four.add_child(Tree("I"))
pt2(tree2)