From c46fbaaebb49f83aa16b9954281b1707b8a3b0a3 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 23 Dec 2015 16:37:04 +0100 Subject: [PATCH] Finished 18 --- 18.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/18.py b/18.py index 749a983..5e9269c 100755 --- a/18.py +++ b/18.py @@ -1,15 +1,13 @@ #!/usr/bin/python import sys -import pdb class Node: - parentNodes = [] - childNodes = [] - weight = 0 - value = 0 def __init__(self,value): + self.parentNodes = [] + self.childNodes = [] + self.weight = 0 self.value = value def calcWeight(self): @@ -31,21 +29,20 @@ nodeMap = [] def buildNodeMap(nodeMap): for i in range(0,len(nodeMap)): for j in range(0,len(nodeMap[i])): - node = nodeMap[i][j] + currentNode = nodeMap[i][j] if(i != len(nodeMap)-1): - node.childNodes.append(nodeMap[i+1][j]) - node.childNodes.append(nodeMap[i+1][j+1]) - + currentNode.childNodes.append(nodeMap[i+1][j]) + currentNode.childNodes.append(nodeMap[i+1][j+1]) if(i != 0): if(j == 0): - node.parentNodes.append(nodeMap[i-1][j]) + currentNode.parentNodes.append(nodeMap[i-1][j]) elif(j == len(nodeMap[i])-1): - node.parentNodes.append(nodeMap[i-1][j-1]) + currentNode.parentNodes.append(nodeMap[i-1][j-1]) else: - node.parentNodes.append(nodeMap[i-1][j]) - node.parentNodes.append(nodeMap[i-1][j-1]) - + currentNode.parentNodes.append(nodeMap[i-1][j]) + currentNode.parentNodes.append(nodeMap[i-1][j-1]) + def dijkstraReverse(nodeMap): for row in nodeMap: @@ -59,8 +56,6 @@ for line in sys.stdin: nodeMap[numRow].append(Node(int(elem))) numRow += 1 -pdb.set_trace() - buildNodeMap(nodeMap) nodeMap.append([]) targetNode = Node(0) @@ -69,12 +64,6 @@ for node in nodeMap[-2]: nodeMap[-1].append(targetNode) -for row in nodeMap: - string = "" - for node in row: - string += str(node) + " " - print string - dijkstraReverse(nodeMap) print "Result is: " + str(targetNode.weight) -- libgit2 0.22.2