functional programming approach
Congratulations.
Honestly, I have difficulties with this kind of algorithm. I have the feeling that you only increment i or j, but at the end you check all the matrix.
Thanks, Jean-Marie. This solution uses recursive calls of the function. So all elements of the matrix are processed.
If you would like to learn more about functional programming principles, I recommend 'Functional Programming Principles in Scala' course by Martin Odersky at Coursera. It starts soon. Actually, I wrote this solution after taking the course a year ago. It is very interesting to look at the same problem from different points of view.
Thanks for your advice.
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))
ans =
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))
ans =
22
|
3 | Pass |
%%
M = hadamard(8);
y_correct = -5;
assert(isequal(shortest_path(M),y_correct))
ans =
-5
|
1966 Solvers
Remove the small words from a list of words.
474 Solvers
Duplicate each element of a vector.
455 Solvers
Find out missing number from a vector of 9 elements
207 Solvers
401 Solvers