Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: needle in a hay-stack solution in Clear category for The Cheapest Flight by przemyslaw.daniel
def cheapest_flight(data, start, stop):
stack, found, best = [(start, 0)], False, 1e9
while stack:
path, price = stack.pop()
if path[-1] == stop:
best, found = min(best, price), True
continue
for a, b, p in data:
stack += [(path+b, price+p)]*(a == path[-1] and b not in path)
stack += [(path+a, price+p)]*(b == path[-1] and a not in path)
return best*found
Feb. 4, 2019
Comments: