def sum_graph(i, j):
'''sum graph [i,j) to determine distance b/w indicies i and j
Automatically perform wraparound'''
if i < j: #normal case, no wraparound
return sum(graph[i:j])
elif i > j: #destination point is earlier in list, wrap around
return sum(graph[i:]) + sum(graph[:j])
else:
return 0
评论列表
文章目录