{"id":2266,"date":"2008-07-03T08:42:59","date_gmt":"2008-07-03T13:42:59","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/07\/03\/puzzler-data-exploration-solution\/"},"modified":"2008-07-03T08:42:59","modified_gmt":"2008-07-03T13:42:59","slug":"puzzler-data-exploration-solution","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/07\/03\/puzzler-data-exploration-solution\/","title":{"rendered":"Puzzler: Data exploration solution"},"content":{"rendered":"This was a fun little puzzle.  I wonder how many people got to the first image, but did not continue to the real solution!\r\n\r\n<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Load the data and take a first look<\/a><\/li>\r\n         <li><a href=\"#2\">What is this stuff?<\/a><\/li>\r\n         <li><a href=\"#3\">Reshape it!<\/a><\/li>\r\n         <li><a href=\"#4\">Tricky one.<\/a><\/li>\r\n         <li><a href=\"#5\">There is pattern here<\/a><\/li>\r\n         <li><a href=\"#6\">Lets try the other reshape<\/a><\/li>\r\n         <li><a href=\"#7\">This is it<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Load the data and take a first look<a name=\"1\"><\/a><\/h3><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">load <span style=\"color: #A020F0\">puzzler.mat<\/span>\r\nplot(c,<span style=\"color: #A020F0\">'.'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/puzzler_01.png\"> <h3>What is this stuff?<a name=\"2\"><\/a><\/h3>\r\n   <p>There is a lot of data, ranges from ~0 to ~255.  Makes me think it is an image that has been made into a vector.  How many\r\n      different ways can this data be reshaped into a matrix?\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">dimensions = factor(numel(c))<\/pre><pre style=\"font-style:oblique\">dimensions =\r\n   419   557\r\n<\/pre><h3>Reshape it!<a name=\"3\"><\/a><\/h3>\r\n   <p>What 'luck'! There is only one pair of prime factors.  Makes you think this is the right path.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">d = reshape(c, dimensions);\r\nimagesc(d)\r\ncolormap(gray)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/puzzler_02.png\"> <h3>Tricky one.<a name=\"4\"><\/a><\/h3>\r\n   <p>We are on the right path, but not there yet.  Those values were suspicious.  Why were there decimal parts for an image.  Let's\r\n      look at the decimal parts.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">e = rem(d,1);\r\nimagesc(e)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/puzzler_03.png\"> <h3>There is pattern here<a name=\"5\"><\/a><\/h3>\r\n   <p>This is the right path, there is pattern here<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">f = e(:);\r\nplot(f,<span style=\"color: #A020F0\">'.'<\/span>);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/puzzler_04.png\"> <h3>Lets try the other reshape<a name=\"6\"><\/a><\/h3>\r\n   <p>There are two possible reshapes, try the other<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">g = reshape(f, fliplr(dimensions));\r\nimagesc(g)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/puzzler_05.png\"> <h3>This is it<a name=\"7\"><\/a><\/h3>\r\n   <p>Now just clean it up a little<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">h = rot90(g, -1);\r\nimagesc(h)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/puzzler_06.png\"> <script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_92d8be39bc0c48b3ac73417cc2c7e148() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='92d8be39bc0c48b3ac73417cc2c7e148 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 92d8be39bc0c48b3ac73417cc2c7e148';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2008 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_92d8be39bc0c48b3ac73417cc2c7e148()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.6<br><\/p>\r\n<\/div>\r\n<!--\r\n92d8be39bc0c48b3ac73417cc2c7e148 ##### SOURCE BEGIN #####\r\n%% Load the data and take a first look\r\n\r\nload puzzler.mat\r\nplot(c,'.')\r\n\r\n%% What is this stuff?\r\n% There is a lot of data, ranges from ~0 to ~255.  Makes me think it is an\r\n% image that has been made into a vector.  How many different ways can this\r\n% data be reshaped into a matrix?\r\n\r\ndimensions = factor(numel(c))\r\n\r\n%% Reshape it!\r\n% What 'luck'! There is only one pair of prime factors.  Makes you think\r\n% this is the right path.\r\n\r\nd = reshape(c, dimensions);\r\nimagesc(d)\r\ncolormap(gray)\r\n\r\n%% Tricky one.\r\n% We are on the right path, but not there yet.  Those values were\r\n% suspicious.  Why were there decimal parts for an image.  Let's look at\r\n% the decimal parts.\r\n\r\ne = rem(d,1);\r\nimagesc(e)\r\n\r\n%% There is pattern here\r\n% This is the right path, there is pattern here\r\n\r\nf = e(:);\r\nplot(f,'.');\r\n\r\n%% Lets try the other reshape\r\n% There are two possible reshapes, try the other\r\n\r\ng = reshape(f, fliplr(dimensions));\r\nimagesc(g)\r\n\r\n%% This is it\r\n% Now just clean it up a little\r\n\r\nh = rot90(g, -1);\r\nimagesc(h)\r\n\r\n\r\n\r\n##### SOURCE END ##### 92d8be39bc0c48b3ac73417cc2c7e148\r\n-->","protected":false},"excerpt":{"rendered":"<p>This was a fun little puzzle.  I wonder how many people got to the first image, but did not continue to the real solution!\r\n\r\n\r\n   Contents\r\n   \r\n      \r\n         Load the data and... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/07\/03\/puzzler-data-exploration-solution\/\">read more >><\/a><\/p>","protected":false},"author":35,"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\/2266"}],"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\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2266"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2266\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}