Created
April 4, 2018 21:32
-
-
Save tugloo1/a299784aba184f7d98ce94e3c15bc3ca to your computer and use it in GitHub Desktop.
whatevssss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_nodes_parent(tree, node_to_evaluate): | |
for i, row in enumerate(tree): | |
if row[node_to_evaluate] == 1: | |
return i | |
else: | |
return None | |
def evaluate_nodes_path(tree, node_to_evaluate, root): | |
paths = [] | |
current_node = node_to_evaluate | |
while True: | |
parent = get_nodes_parent(tree, current_node) | |
if parent == root: | |
paths.append(parent) | |
return paths | |
elif parent is None: | |
return paths | |
else: | |
paths.append(parent) | |
current_node = parent | |
def question4(tree, root, node1, node2): | |
node1_path = evaluate_nodes_path(tree, node1, root) | |
node2_path = evaluate_nodes_path(tree, node2, root) | |
if node1_path.__len__() < node2_path.__len__(): | |
for node in node1_path: | |
if node in node2_path: | |
return node | |
else: | |
for node in node2_path: | |
if node in node1_path: | |
return node | |
a = question4([[0, 1, 0, 0, 0], | |
[0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0], | |
[1, 0, 0, 0, 1], | |
[0, 0, 0, 0, 0]], | |
3, | |
1, 4) | |
print(a) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment