Proplem with min_path_owl


My min_energy_column works for all pub test except owl. With owl I get column 0 but correct would be according to ref. column = 149.
This is how I understand min energy column:
Go through the last row of the matrix, find the minimum energy and if it occurs more than once take the column with the lowest x value (I solve this by going through the array from left to right and only looking at smaller values and ignoring equal ones).

Have you tried debugging to isolate the problem? Are you wrongly computing the total energy or incorrectly finding the lowest x-index?

It must be the calculate_min_energy_column. If I replace the return with return 149, I pass the public test min_path_owl.
I debugged the test with the method described by Marcel. So I could find out, that I take column 0 as minimum and don’t find a smaller energy value in the line. But this should be the case at column 149 at the latest, because this is the last value in the owl path (line 307).

Well, that’s unfortunate. Bugs in that method can be hard to find.

As a general (or more specific :stuck_out_tongue:) hint, bugs become easier to see when code becomes more readable. Formatting really helps with this. Luckily, VSCode can do this automatically by pressing Ctrl+Shift+I.

Note that this changes the indentation. To fix this, add a .clang-format file to your project root, containing the following:

BasedOnStyle: LLVM
IndentWidth: 4

Furthermore, I would recommend enabling the Format On Paste, Format On Type and Format On Save settings in VSCode so that your code always magically formats itself.

Also, you can actually peek into your energy matrix during debugging to check which values are in there. To do so, just evaluate the expression energy[x * w + h]. Learn more about evaluating expressions (and all the other fancy features your debugger has) here.

1 Like

Hello Johannes, thank you very much for your help! But I have one question: Why energy[x*w+h]? For a 3x3 matrix and column x = 2 I would be at energy[9] and thus no longer in the array.
Also, the following error is thrown when debugging (I am using VS code in the VM and have extracted the zip)

Sorry, I meant x*w+y. But that was just a dummy value to show that you can put arbitrary expressions here.

Hello Johannes, I have found my bug! In fact, my energy was wrong. But I am very surprised that the other tests worked then, probably because the calculation was proportional everywhere and the min_path was found somehow. Thanks for your support, especially Saturday to Sunday night ! :smiley: