Question: The answer box has been preloaded with code that reads a file of integer weights and computes the minimum cost path between the bottom row

The answer box has been preloaded with code that reads a file of integer weights and computes the minimum cost path between the bottom row and the top row. The code uses a direct recursive implementation of the recurrence relation given in the lecture notes.
But ... there are two problems with the code.
Firstly, it has a simple logic error and fails even on a simple test case. For example, the output from the first test is 5 but the input file is
321
213
123
for which the answer should clearly be 3. The other problem is that it times out on larger grids, such as a 90 x 90 grid.
We'll deal with the time-out problem in the next question. Your task in this question is just to fix that bug so that code passes the trivial test above and the simple 5 x 5 example from the lecture notes:
67478
76114
35782
26702
73561
The bug is very simple, involving just one tiny bit of text (e.g., a word or a number) but it is not all that obvious. You will probably have to use some simple debugging techniques to locate it. Please keep in mind that the purpose of this exercise is to help you to understand the algorithm, so asking someone what the bug is will likely destroy the learning outcome.
For this question, pylint compliance is required although docstrings aren't necessary and name checking is turned off.
Resubmission penalties are turned off for this question.
For example:
Test Result
print(file_cost('checkerboard.trivial.in'))
3
print(file_cost('checkerboard.small.in'))
8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!