Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here we will check the proposed journey path is possible given the provided pony capacity, pony assignment to route segments, and village elevation. The journey

Here we will check the proposed journey path is possible given the provided pony capacity, pony assignment to route segments, and village elevation.

The journey path is provided, it should always start at the start village (0,0) and finish at the final village (M,N). The final point (M,N) is at the corner - that is, M and N are the maximum indicies that x and y can take.

Write a function check_path(elevations, path, capacities, assignments) Arguments:

elevations a list of rows, where each row is a list of cells, each cell (village) is provided with its absolute elevation level

path a list of tuples, each tuple provides (x,y) coordinates for each path segment to take the trolley on. Should start with (0,0) and finish at (M,N)

capacities a list of available pony types

assignments a list of assignments (tuples) for each pair of ponies to a path segment.

The function returns None if the assigned ponies are capable of getting from the initial (0,0) point to the destination using the provided path. Otherwise, it should return a tuple with a cell coordinate and associated error message string.

If there are multiple possible error messages, return the first one in the error message list.

The possible error messages are provided below. Note that the (M,N) message requires replacing (M,N) with the appropriate values.

Cell coordinate is out of bounds A cell listed in path is out of map boundaries according to cell_elevations
Path should start at (0,0) coordinate The first element in the path isn't (0,0)
Path should end at (M, N) coordinate The path's last element isn't the final village (replace M, N in the error message with values for the current data, where M and N are the maximum indicies that x and y can take).
Illegal move The path contains any move other than plus one x coordinate or plus one y coordinate.(*)
Insufficient capacity assignment Assigned pony capacity isn't enough to overcome an elevation raise on the way to the next cell in path. (*)
Exceeding pony limit A pony assignment for a move contains more than two ponies(*)

(*) Whenever an error is associated to a move (source cell -> destination cell), return the move's source cell as the error_cell.

If multiple errors occur, report one listed first in the description table; of errors of the same kind, return one occurring earlier in a path

>>> # Weve got ponies of three types >>> pony_capacities = [17, 37, 73] >>> # The path contains 7 cells, requires 6 moves. The map size is 2x6. >>> journey_path = [(0,0), (0,1), (0,2), (0,3), (1,3), (1,4), (1,5)] >>> # Ponies assigned for each move (matched by corresponding indices). Every time we need a pair of them. >>> pony_assignments = [(73, 73)] * 6 >>> # Absolute elevation levels for each cell (village) on the map (2x6 = 12) >>> village_elevations = [[100, 200, 300, 400, 100, 600], [0, 100, 200, 300, 400, 500]] >>> result = check_path(village_elevations, journey_path, pony_capacities, pony_assignments) >>> print(result) None >>> journey_path = [(0,0), (0,1), (0,2), (0,3), (1,3), (1,4), (1,6)] >>> check_path(village_elevations, journey_path, pony_capacities, pony_assignments) ((1, 6), 'Cell coordinate is out of bounds') >>> journey_path = [(0,1), (0,1), (0,2), (0,3), (1,3), (1,4), (1,5)] >>> check_path(village_elevations, journey_path, pony_capacities, pony_assignments) ((0, 1), 'Path should start at (0,0) coordinate') >>> pony_assignments = [(73, 17)] * 6 >>> journey_path = [(0,0), (0,1), (0,2), (0,3), (1,3), (1,4), (1,5)] >>> check_path(village_elevations, journey_path, pony_capacities, pony_assignments) ((0, 0), 'Insufficient capacity assignment')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Have I incorporated my research into my outline effectively?

Answered: 1 week ago