''' For Halloween in your neighborhood, you get a list with adresses randomly distributed over a map. It is up to you to find the optimal route to pass by every house and walk the shortest distance overall. Exercise A: Make a function named `dist` which calculates the distance between the current location and a future location. Hint: you might want to use `np.sqrt`. ''' current_location = [0,0] future_location = [3,4] def dist (current, future): # Your code here ''' Exercise B: Now instead of getting one future location, you get an array with locations. Make a function `best_location` to find the best future location, which is closest to the current location. Hint: you might want to use `np.where`, and feel free to reuse (part of) your above `dist` function. ''' future_locations= np.array( [ [10,0],[10,5] , [10,-5],[-8,0], [-8,4],[-8,-4],[-2,1],[-5,2.5],[3,1.5],[7,3.5]]) # print(np.shape(future_locations)) def best_location(current, future): # Your code here ''' Exercise C: By using the previous `best_location` function, write code to automatically find the most optimal route along all `future_locations`. Do this by repeatedly finding the best next step. An array, called `route`, should be generated, which is the optimally rearranged version of `future_locations`, starting and ending at current location [0,0]. Whether you are correct can be directly seen after plotting the route below. Hint: you might want to use `numpy.delete(arr, obj, axis=None)` * arr: Input array * obj: Row or column number to delete * axis: Axis to delete ''' def find_best_location(current,future): route = np.zeros((len(future)+2, 2)) # Your code here return route ''' With this code you can visualize your route: ''' route = find_best_location(current_location, future_locations) print(route) import matplotlib.pyplot as plt plt.plot(route[:,0],route[:,1],'*-')