You will model a delivery problem in code and search all the whole-number plans for the cheapest one.
The idea. Depot D1 holds crates and depot D2 holds . Shop S1 needs crates and shop S2 needs . Let crates go from D1 to S1 and from D1 to S2. Then D2 sends to S1 and to S2. The cost per crate in rupees is from D1 to S1, from D1 to S2, from D2 to S1 and from D2 to S2.
Your tasks.
is_valid(x, y). Return True if all four shipments are at least , D1 sends at most crates and D2 sends at most .total_cost(x, y). Return the total cost in rupees of the four shipments.best_plan(). Try every whole number x from 0 to 25 and y from 0 to 35. Return (lowest cost, x, y) among the valid plans.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…