Cody

# Problem 1049. Path of least resistance

Solution 705580

Submitted on 23 Jul 2015 by Tomasz
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% 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 ]; y_correct = 35; assert(isequal(shortest_path(M),y_correct))

p = 7 p = 15 p = 16 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 15 p = 14 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 11 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 21 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 7 p = 12 p = 20 p = 28 p = 26 p = 7 p = 12 p = 20 p = 28 p = 31 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 31 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 7 p = 12 p = 20 p = 28 p = 26 p = 7 p = 12 p = 20 p = 28 p = 31 p = 7 p = 12 p = 20 p = 28 p = 26 p = 29 p = 7 p = 12 p = 20 p = 28 p = 26 p = 27 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 7 p = 12 p = 20 p = 28 p = 26 p = 7 p = 12 p = 20 p = 28 p = 31 p = 33 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 7 p = 12 p = 20 p = 28 p = 26 p = 7 p = 12 p = 20 p = 28 p = 31 p = 7 p = 12 p = 20 p = 28 p = 26 p = 29 p = 7 p = 12 p = 20 p = 28 p = 26 p = 27 p = 7 p = 12 p = 20 p = 28 p = 26 p = 29 p = 30 p = 7 p = 12 p = 20 p = 28 p = 26 p = 29 p = 36 p = 7 p = 15 p = 7 p = 12 p = 7 p = 7 p = 7 p = 12 p = 20 p = 7 p = 12 p = 16 p = 7 p = 12 p = 20 p = 28 p = 7 p = 12 p = 20 p = 21 p = 7 p = 12 p = 20 p = 28 p = 26 p = 7 p = 12 p = 20 p = 28 p = 31 p = 7 p = 12 p = 20 p = 28 p = 26 p = 29 p = 7 p = 12 p = 20 p = 28 p = 26 p = 27 p = 35

2   Pass
%% M = [6 8 5 5 3 5 4 8 0 5 9 6 9 3 2 3 1 1 2 6 8 1 6 8 3 ]; y_correct = 22; assert(isequal(shortest_path(M),y_correct))

p = 5 p = 8 p = 8 p = 13 p = 5 p = 8 p = 8 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 8 p = 16 p = 5 p = 8 p = 8 p = 13 p = 5 p = 8 p = 8 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 8 p = 16 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 6 p = 7 p = 5 p = 6 p = 12 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 16 p = 5 p = 8 p = 8 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 8 p = 16 p = 21 p = 5 p = 8 p = 8 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 8 p = 16 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 6 p = 7 p = 5 p = 6 p = 12 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 16 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 6 p = 7 p = 5 p = 6 p = 12 p = 5 p = 6 p = 7 p = 10 p = 5 p = 6 p = 7 p = 16 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 6 p = 7 p = 5 p = 6 p = 12 p = 17 p = 5 p = 8 p = 8 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 8 p = 16 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 5 p = 6 p = 7 p = 5 p = 6 p = 12 p = 5 p = 8 p = 5 p = 6 p = 5 p = 14 p = 16 p = 22

3   Pass
%% M = hadamard(8); y_correct = -5; assert(isequal(shortest_path(M),y_correct))

p = 0 p = -1 p = -2 p = -3 p = -4 p = -3 p = -2 p = 0 p = -1 p = -2 p = -3 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = -5 p = 0 p = -1 p = -2 p = -3 p = -4 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = -5 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = -5 p = -4 p = 0 p = -1 p = -2 p = -3 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = -5 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = -4 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = -3 p = -3 p = 0 p = -1 p = -2 p = -3 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = -2 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -2 p = 0 p = -1 p = -3 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = -4 p = 0 p = -1 p = -2 p = 0 p = -1 p = 0 p = -1 p = 0 p = 0 p = 0 p = -1 p = -3 p = -3 ...