Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Did you think a traveling salesman? missed ! solution in Clear category for Delivery Drone by rybld2
from typing import List
def delivery_drone(orders: List[int]) -> int:
from itertools import permutations
def compte(chem):
departure, returns=(0,), () # 0 for departure
for c in chem :
departure += c
returns +=c
returns += (0,) # 0 for return
return sum([abs(x-y) for (x,y) in zip(departure, returns)])
orders = [(i, d) for i, d in enumerate(orders) if d]
res = sorted([ p for p in permutations(orders)], key=compte) #shortest needed
return compte(res[0])
Sept. 22, 2021