VBA – Find the Best Way Through a Matrix, going Right and Down

Have you ever tought what is the best way to go in a matrix, in order to collect as many points as possible, if you are allowed to go only to the right and down?

Imagine some matrix like the yellow cells on the screenshot below. Your task is to go from the A1 cell to the G8. With as much as possible points.



The correct way is shown on the next matrix, in red.  The solution is quite simple and thus beautiful – you have to find which way is the best to achieve a given cell and calculate it for all cells. E.g. cell B2 with value 3 must be achieved from B1 and not from A2. In B1 we have value 4 and in A2 we have value 2. And this should be calculated for the whole matrix.  Using the matrix next to it 🙂

Pretty much that is all. Here is a small YouTube video I made, randomizing the matrices, just for some kind of fun 🙂

The code is here:

And the file is this one.

In GitHub.

Enjoy it!