Example #1
0
 def test_tree_nodes(self):
     t1 = tree_node(None, None, 0)
     self.assertEquals(t1.value, 0)
     
     t2 = tree_node(None, None, 5)
     self.assertEquals(t2.value, 5)
     
     t3 = tree_node(t1, None, 10)
     self.assertEquals(t3.value, 10)
     
     t3 = tree_node(None, t2, 10)
     self.assertEquals(t3.value, 15)
     
     t3 = tree_node(t1, t2, 10)
     self.assertEquals(t3.value, 15)
Example #2
0
def get_max_tree_node_path(grid):
    
    # Hold all nodes to reference parents when creating children
    branches = []
    
    for rowIndex in xrange(0, len(grid), 1):
        branch = []
        
        row = grid[rowIndex]
        
        for columnIndex in xrange(0, len(row), 1):
            leftParent, rightParent = None, None
            if rowIndex > 0:
                parentBranch = branches[rowIndex-1]
                
                if columnIndex < len(row) - 1:        
                    rightParent = parentBranch[columnIndex]
                
                if columnIndex > 0:
                    leftParent = parentBranch[columnIndex - 1]
                
            node = tree_node(leftParent, rightParent, row[columnIndex])
            branch.append(node)            
            
        branches.append(branch)
        
    return max(n.value for n in branches[-1])