Deke1604 / LC1-Assessment-DEKE

MIT License
0 stars 1 forks source link

Engineering problem #3

Open Deke1604 opened 1 year ago

Deke1604 commented 1 year ago

Let's say we're trying to find the shortest route for a pizza delivery driver to visit all of his customers in a given city. The dynamic programming algorithm would work like this:

Here's the complete code for the function: def find_shortest_path(points): distance_matrix = [[0 for row in range(len(points))] for column in range(len(points))] for i in range(len(points)): for j in range(i + 1, len(points)): distance_matrix[i][j] = distance_to_point(points[i], points[j])

Now that we have the function to find the shortest path, we can use it to find the shortest route for our pizza delivery driver. We'll create a list of points, representing the four customers, and pass it to the find_shortest_path() function. The code will look like this:

points = [A, B, C, D] shortest_route = find_shortest_path(points) This will return the shortest path between the four customers.

The result of this code will be a list of distances, in the form of a route, like this: shortest_route = [A, B, C, D, A] This means that the shortest route from A to B, to C, to D, and back to A is the shortest route between all four customers.