33
44class HelloGraphChallenge (Challenge ):
55 """
6- Given: Two nodes and a list of edges
6+ Given: Two nodes and a list of edges denoting a path
77 Return: Graph between the nodes and it's weight
88 """
99
@@ -23,23 +23,22 @@ class HelloGraphChallenge(Challenge):
2323 '''
2424
2525 def build (self ):
26+ self .model = self .lines_to_graph (start = 2 )
2627 self .model .start = self .line_to_integer (0 )
2728 self .model .stop = self .line_to_integer (1 )
28- self .model .graph = dict ()
29- for edge in self .edges (2 ):
30- self .model .graph [edge .tail ] = (edge .head , edge .weight )
3129
3230 def calc (self ):
33- head = None
3431 tail = self .model .start
35- self .result .graph = [tail ]
32+ self .result .path = [tail ]
3633 self .result .weight = 0
3734 while tail != self .model .stop :
38- self .result .weight += self .model .graph [tail ][1 ]
39- tail = self .model .graph [tail ][0 ]
40- self .result .graph .append (tail )
35+ # it's a path, just one way to go
36+ head = self .model .edges [tail ][0 ]
37+ self .result .path .append (head )
38+ self .result .weight += self .model .weights [(tail , head )]
39+ tail = head
4140
4241 def format (self ):
43- self .output = self .format_path (self .result .graph )
42+ self .output = self .format_path (self .result .path )
4443 self .output += self .br
4544 self .output += str (self .result .weight )
0 commit comments