Cody

Problem 1049. Path of least resistance

Find the length of the shortest path through the matrix from the top left to bottom right corner. You may move right, down, or diagonally right-down one element at a time. The length of the path is the sum of the elements you pass through.

E.g.

 M = [*8      6      10      10     4     7     7      7
       9     *1      10      5      9     0     8      2
       1      3     *2       8      8     8     7      7
       9      5      10     *1     *10   *9    *4     *0 ]; 
>> shortest_path(M)
ans =
      35

The shortest path through this matrix has length 35. Each element along the path is marked with a *

Solution Stats

64.2% Correct | 35.8% Incorrect
Last solution submitted on Sep 12, 2016

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more