Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple brute force solution in Clear category for Delivery Drone by juestr
from typing import List
from itertools import permutations
def delivery_drone(orders: List[int]) -> int:
def distance(deliveries, pos=0):
if deliveries:
(start, end), *rest = deliveries
return abs(pos - start) + abs(start - end) + distance(rest, pos=end)
else:
return pos
deliveries = ((start, end) for start, end in enumerate(orders) if end)
return min(map(distance, permutations(deliveries)))
July 24, 2019