Cool problem. Optimal solutions sometimes appear if moving up is enabled.
functional programming approach
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.
Remove any row in which a NaN appears
Find the two most distant points
What is the next step in Conway's Life?
Remove NaN ?
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
Elapsed time is -0.005204 seconds.
What day is it?
Find the longest match inside two strings
Exact binary matrix factorization
Partial sorting algorithm
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office