I am trying something new this week: the MATLAB Puzzler.
Rather than just work one of the Practical Examples directly, I am doing it in two parts. The first I will pose the MATLAB puzzler and say how much code it took me to solve it. This is not a contest, so don’t try to solve this in less code (unless you think that would be fun). I give the benchmark so that if you find yourself using 50 lines of code you know there is a simpler way! Just try to solve the puzzle with clear code and sharpen your skills.
In the second video, I explain my thought process in the algorithm and then implement it. I posed this problem as a test to Jiro. With heckling, he was able to solve this puzzler in 14 minutes and the same amount of code.
Here is the code you need for the test matrix:
a=[
0 1 1 0 0
0 0 1 0 1
0 0 1 0 0
0 0 1 0 1
0 0 1 0 1]
The above is a good test matrix, but you can generate more random ones with this:
a = full(round(sprand(5,5,0.8)))
I was surprised that Jiro and I took very different paths to solving this problem. Post your solutions in the comments area along with how long it took you to solve.
[NOTE] After a week, a wrap-up was posted for this Puzzler. [click here]
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.