{"id":2183,"date":"2008-03-25T09:22:08","date_gmt":"2008-03-25T14:22:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/25\/matlab-puzzler-removing-columns-and-rows-from-binary-matrices\/"},"modified":"2016-11-17T10:39:48","modified_gmt":"2016-11-17T15:39:48","slug":"matlab-puzzler-removing-columns-and-rows-from-binary-matrices","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/25\/matlab-puzzler-removing-columns-and-rows-from-binary-matrices\/","title":{"rendered":"MATLAB Puzzler: Removing columns and rows from binary matrices"},"content":{"rendered":"<p>I am trying something new this week: the MATLAB Puzzler.<\/p>\n<p>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&#8217;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.<\/p>\n<p>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.<\/p>\n<p>Here is the code you need for the test matrix:<\/p>\n<p><code>a=[<br \/>\n0 1 1 0 0<br \/>\n0 0 1 0 1<br \/>\n0 0 1 0 0<br \/>\n0 0 1 0 1<br \/>\n0 0 1 0 1]<\/code><\/p>\n<p>The above is a good test matrix, but you can generate more random ones with this:<\/p>\n<p><code>a = full(round(sprand(5,5,0.8)))<\/code><\/p>\n<p><embed src=\"https:\/\/blogs.mathworks.com\/images\/pick\/\/FlashVideos\/FlowPlayer.swf?config=%7Bembedded%3Atrue%2CplayList%3A%5B%7BsuggestedClipsInfoUrl%3A%2788%20see%20also%2Etxt%27%2Curl%3A%2788%20Puzzler%20Remove%20columns%2Eflv%27%7D%5D%2CbaseURL%3A%27http%3A%2F%2Fblogs%2Emathworks%2Ecom%2Fimages%2Fpick%2FFlashVideos%2F%27%2CsplashImageFile%3A%2788%20Puzzler%20Remove%20columns%2Ejpg%27%2Cloop%3Afalse%2CinitialScale%3A%27fit%27%2CshowFullScreenButton%3Afalse%2CautoBuffering%3Afalse%2CmenuItems%3A%5Bfalse%2Cfalse%2Cfalse%2Cfalse%2Cfalse%2Ctrue%5D%2CautoPlay%3Afalse%7D\" type=\"application\/x-shockwave-flash\" width=\"500\" height=\"400\"><\/embed><\/p>\n<p><embed src=\"https:\/\/blogs.mathworks.com\/images\/pick\/\/FlashVideos\/FlowPlayer.swf?config=%7Bembedded%3Atrue%2CplayList%3A%5B%7BsuggestedClipsInfoUrl%3A%2789%20see%20also%2Etxt%27%2Curl%3A%2789%20Puzzler%20Remove%20columns%20answer%2Eflv%27%7D%5D%2CbaseURL%3A%27http%3A%2F%2Fblogs%2Emathworks%2Ecom%2Fimages%2Fpick%2FFlashVideos%2F%27%2CsplashImageFile%3A%2789%20Puzzler%20Remove%20columns%20answer%2Ejpg%27%2Cloop%3Afalse%2CinitialScale%3A%27fit%27%2CshowFullScreenButton%3Afalse%2CautoBuffering%3Afalse%2CmenuItems%3A%5Bfalse%2Cfalse%2Cfalse%2Cfalse%2Cfalse%2Ctrue%5D%2CautoPlay%3Afalse%7D\" type=\"application\/x-shockwave-flash\" width=\"500\" height=\"400\"><\/embed><br \/>\nI 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.<\/p>\n<p><strong>[NOTE] After a week, a wrap-up was posted for this Puzzler.\u00a0<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying something new this week: the MATLAB Puzzler.<br \/>\nRather 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&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/25\/matlab-puzzler-removing-columns-and-rows-from-binary-matrices\/\">read more >><\/a><\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,6,15,2],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2183"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2183"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2183\/revisions"}],"predecessor-version":[{"id":7302,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2183\/revisions\/7302"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}