{"id":2295,"date":"2008-08-18T09:38:57","date_gmt":"2008-08-18T14:38:57","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/08\/18\/puzzler-find-largest-connected-island\/"},"modified":"2008-08-18T09:38:57","modified_gmt":"2008-08-18T14:38:57","slug":"puzzler-find-largest-connected-island","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/08\/18\/puzzler-find-largest-connected-island\/","title":{"rendered":"Puzzler: Find largest connected island"},"content":{"rendered":"<p>Every now and then we send MATLAB challenges through the department to help sharpen our programming skills.  What amazes me is the sheer variety of solutions that people come up with. <\/p>\n<p>Today, I have a challenge for the community here.  Given a matrix of random, positive, whole numbers, find the largest group of identical, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Connected_Component_Labeling\">four connected<\/a> values.<\/p>\n<p>If there are two groups tied for the same size, choose the largest valued.  If there is still a tie, it is a free choice which to use.  Simply return a binary matrix with ones where the island of connected pixels is.<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/island.jpg' alt='island.jpg' \/><\/p>\n<p>I suspect that this challenge will be much easier for people with access to the <a href=\"https:\/\/www.mathworks.com\/products\/image\/\">Image Processing Toolbox<\/a>.  I am curious to see what kind of creative solutions people will find with and without the toolbox.  <\/p>\n<p>Here is the starter code:<\/p>\n<p><code><br \/>\nn = 10; % size of matrix<br \/>\nv =  9; % max value of matrix, different values give bigger islands<br \/>\na = round(rand(n)*v);<br \/>\nflag = mySolver(a); % mySolver will return a binary matrix<br \/>\n<\/code><\/p>\n<p>Your mission, write mySolver.m and place it in the comment section.<\/p>\n<p>When you post your code in the comments, please use the tags<\/p>\n<pre><code>\r\n&lt;pre> &lt;code>\r\n\r\nall the code so someone can just copy and paste it from the comments.\r\n\r\n&lt;\/code> &lt;\/pre>\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Every now and then we send MATLAB challenges through the department to help sharpen our programming skills.  What amazes me is the sheer variety of solutions that people come up with.<br \/>\nToday, I have&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/08\/18\/puzzler-find-largest-connected-island\/\">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":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2295"}],"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=2295"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2295\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}