{"id":875,"date":"2014-01-20T12:00:24","date_gmt":"2014-01-20T17:00:24","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=875"},"modified":"2016-07-01T12:28:00","modified_gmt":"2016-07-01T17:28:00","slug":"magic-stars","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2014\/01\/20\/magic-stars\/","title":{"rendered":"Magic Stars"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>Magic Stars are a little like Magic Squares.  My grandson was introduced to them in his junior high school math class.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#37a65b93-31fc-4962-843b-af18ba5a7f2d\">Family Enterprise<\/a><\/li><li><a href=\"#507a1e85-0732-4c2a-a4c4-1874acef4223\">Observatory<\/a><\/li><li><a href=\"#984ac58e-89b2-42bb-a009-e5e5da0efb3c\">Basic Stars<\/a><\/li><li><a href=\"#90491562-b7a8-449b-801a-b2209e700737\">Magic Stars<\/a><\/li><li><a href=\"#2ef47523-b286-4d6b-ac01-db4d1863c10c\">Five-point<\/a><\/li><li><a href=\"#30333d31-363e-45b5-add6-f8933075c431\">Rotations and reflections<\/a><\/li><li><a href=\"#26be6765-7a94-4806-a09e-652c1b42083b\">More five-point stars<\/a><\/li><li><a href=\"#f618ad8f-c450-4c6c-b118-5d71f5cee7e8\">Six-point<\/a><\/li><li><a href=\"#1d8fe3eb-beef-4cfe-8503-3f6e8dab829c\">Further reading<\/a><\/li><\/ul><\/div><h4>Family Enterprise<a name=\"37a65b93-31fc-4962-843b-af18ba5a7f2d\"><\/a><\/h4><p>This post is a family enterprise.  My grandson Ben heard about five-point magic stars in his junior high school math class, where they tackled them by hand.  Ben told his mom Kam, my daughter, who wrote a MATLAB program, and then told me.<\/p><h4>Observatory<a name=\"507a1e85-0732-4c2a-a4c4-1874acef4223\"><\/a><\/h4><p>Here is the function that I use to view the stars.<\/p><pre class=\"codeinput\">   type <span class=\"string\">observatory<\/span>\r\n<\/pre><pre class=\"codeoutput\">\r\n   function observatory(v)\r\n   % observatory  View Magic Stars.\r\n   % observatory(v), where v is a vector of 10 or 12 integers.\r\n      clf\r\n      n = length(v)\/2;\r\n      d = pi\/n;\r\n      t = 0:2*n-1;\r\n      r0 = .42 + .20*(n == 5);\r\n      r = 1 - r0*(mod(t,2)==1);\r\n      x = r.*sin(t*d);\r\n      y = r.*cos(t*d);\r\n      p = plot(x,y,'o','markersize',28,'markeredgecolor',[0 0 .66]);\r\n      axis(1.25*[-1 1 -1 1])\r\n      axis square\r\n      set(gca,'xtick',[],'ytick',[])\r\n      if n == 5\r\n         h = line([x(1:4:2*n) x(3:4:2*n) x(1)], ...\r\n                  [y(1:4:2*n) y(3:4:2*n) y(1)]);\r\n      elseif n == 6\r\n         h = [line([x(1:4:2*n) x(1)],[y(1:4:2*n) y(1)])\r\n              line([x(3:4:2*n) x(3)],[y(3:4:2*n) y(3)])];\r\n      else\r\n         error('Can only observe 10 or 12 points')\r\n      end\r\n      set(h,'color',[0 .66 .66])\r\n      for k = 1:2*n\r\n         text(x(k),y(k),int2str(v(k)),'fontsize',18,'horiz','center')\r\n      end\r\n   end\r\n<\/pre><h4>Basic Stars<a name=\"984ac58e-89b2-42bb-a009-e5e5da0efb3c\"><\/a><\/h4><p>There are lots of kinds of magic stars.  Here are the most basic. Draw a regular <i>n<\/i>-point star the way you learned to draw a 5-point star. Connect the <i>n<\/i> points evenly spaced around a circle by <i>n<\/i> lines between alternate points.  This produces a regular <i>n<\/i>-gon in the interior. The vertices of the outer points, together with the vertices of the interior polygon, gives you <i>2n<\/i> points.  Here are the five and six point stars, with the points numbered in consecutive clockwise order.<\/p><pre class=\"codeinput\">   observatory(1:10)\r\n   snapnow\r\n\r\n   observatory(1:12)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_01.png\" alt=\"\"> <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_02.png\" alt=\"\"> <h4>Magic Stars<a name=\"90491562-b7a8-449b-801a-b2209e700737\"><\/a><\/h4><p>To turn one of these stars into a magic star, you need to rearrange the numbers so that the sums along each of the <i>n<\/i> lines are equal, just like the sums along the rows and columns in a magic square.  It turns out that this is impossible for the 5-point star and we will have to modify the rules.  But it is possible for the 6-point star.<\/p><h4>Five-point<a name=\"2ef47523-b286-4d6b-ac01-db4d1863c10c\"><\/a><\/h4><p>The sum of the integers from 1 to 10 is <i>S = 55<\/i>.  There are five lines in the 5-point star and each integer is involved in the intersection of two of these lines, so if the sums along each line are to be equal, that sum must be <i>L = (2\/5)S = 22<\/i>.  We are seeking a permutation <i>p<\/i> of the first ten integers that satisfies the five equations.<\/p><p>$$ p_1+p_2+p_4+p_5 = L $$<\/p><p>$$ p_3+p_4+p_6+p_7 = L $$<\/p><p>$$ p_5+p_6+p_8+p_9 = L $$<\/p><p>$$ p_7+p_8+p_{10}+p_1 = L $$<\/p><p>$$ p_9+p_{10}+p_2+p_3 = L $$<\/p><p>The subscripts in each of these equations can be read off by following one of the lines across the star.<\/p><p>An exhaustive search of all 10! permutations of the integers 1 through 10 reveals that there are no solutions to these equations, so no perfect five-point magic star exists.<\/p><p>But do not despair.  Relax the rules by allowing more players. Ben's class was given the challenge of finding a magic 5-point star using nine of the ten integers between 1 and 10, and also using 12.  They had to be careful. The sum <i>S<\/i> needs to be a multiple of 5 because the line sum is always going to be <i>L = (2\/5)S<\/i>.  So they learned that they had to exclude either 2 or 7.  Let's first try leaving out the 7.<\/p><p>I'm going to give the integer 12 a special role by fixing it at the apex of the star.  This eliminates all the stars that are obtained from the ones that I will find by simple rotations, and it also eliminates all the stars where 12 is at an internal point.  It leaves only nine integers left to permute.  Here are the parameters.<\/p><pre class=\"codeinput\">   clear\r\n   n = 5;\r\n   v = [1:6 8:10];   <span class=\"comment\">% Omit 7.<\/span>\r\n   S = sum(v) + 12\r\n   L = 2\/n*S\r\n<\/pre><pre class=\"codeoutput\">\r\nS =\r\n\r\n    60\r\n\r\n\r\nL =\r\n\r\n    24\r\n\r\n<\/pre><p>Use the MATLAB function <tt>perms<\/tt> to generate all possible permutations of the nine free integers.<\/p><pre class=\"codeinput\">   P = perms(v);\r\n<\/pre><p>Insert a column of 12's in front to produce a matrix with 9! (that's 9 factorial) rows and 10 columns.<\/p><pre class=\"codeinput\">   P = [12*ones(size(P,1),1) P];\r\n   sizeP = size(P)\r\n<\/pre><pre class=\"codeoutput\">\r\nsizeP =\r\n\r\n      362880          10\r\n\r\n<\/pre><p>See how much storage we're using.<\/p><pre class=\"codeinput\">   whos\r\n<\/pre><pre class=\"codeoutput\">  Name            Size               Bytes  Class     Attributes\r\n\r\n  L               1x1                    8  double              \r\n  P          362880x10            29030400  double              \r\n  S               1x1                    8  double              \r\n  n               1x1                    8  double              \r\n  sizeP           1x2                   16  double              \r\n  v               1x9                   72  double              \r\n\r\n<\/pre><p>My laptop can handle 29 megabytes.<\/p><p>We are ready to search for the solutions.<\/p><pre class=\"codeinput\">   f = find(P(:,1)+P(:,2)+P(:,4)+P(:,5) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,3)+P(:,4)+P(:,6)+P(:,7) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,5)+P(:,6)+P(:,8)+P(:,9) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,7)+P(:,8)+P(:,10)+P(:,1) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,9)+P(:,10)+P(:,2)+P(:,3) == L)\r\n<\/pre><pre class=\"codeoutput\">\r\nf =\r\n\r\n       85418\r\n       99312\r\n      133775\r\n      139937\r\n      205213\r\n      222969\r\n      257655\r\n      272091\r\n      284491\r\n      298403\r\n      322934\r\n      361090\r\n\r\n<\/pre><p>Out of the over one-third of a million permutations, these are the indices that satisfy the five line equations.  Here are those solutions.<\/p><pre class=\"codeinput\">   P = P(f,:)\r\n<\/pre><pre class=\"codeoutput\">\r\nP =\r\n\r\n    12     8     9     1     3    10     4     6     5     2\r\n    12     8     5     3     1    10     6     4     9     2\r\n    12     6    10     4     2     9     1     8     5     3\r\n    12     6     5     2     4     9     8     1    10     3\r\n    12     4     9     2     6     5     8     3    10     1\r\n    12     4    10     6     2     5     3     8     9     1\r\n    12     3     5     8     1     9     2     4    10     6\r\n    12     3    10     1     8     9     4     2     5     6\r\n    12     2     9     4     6    10     1     3     5     8\r\n    12     2     5     6     4    10     3     1     9     8\r\n    12     1     9     8     3     5     2     6    10     4\r\n    12     1    10     3     8     5     6     2     9     4\r\n\r\n<\/pre><p>Twelve solutions were found. The last solution has the integers from 1 to 5 in the interior.<\/p><pre class=\"codeinput\">   p = P(12,:)\r\n   observatory(p)\r\n<\/pre><pre class=\"codeoutput\">\r\np =\r\n\r\n    12     1    10     3     8     5     6     2     9     4\r\n\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_03.png\" alt=\"\"> <h4>Rotations and reflections<a name=\"30333d31-363e-45b5-add6-f8933075c431\"><\/a><\/h4><p>Our search for stars formed from the integers from 1 to 12, leaving out 7 and 11, found 12 solutions.  But the last six are actually reflections of the first six.  Look at the solution array P, and ignore the first column with the 12s.  If you read the last six rows backwards, from right to left, you will get the first six rows in a different order. You can also think of this as clockwise versus counter clockwise indexing.<\/p><p>So, we have found six distinctly different solutions with 12 at the apex. There are three kinds of transformations that can be made on these solutions.  This will produce all of the possible magic stars that can be made from this set of integers.<\/p><p><i>Reflect<\/i>, about the vertical axis.<\/p><pre class=\"codeinput\">   p = p([1 10:-1:2])\r\n   observatory(p)\r\n   snapnow\r\n<\/pre><pre class=\"codeoutput\">\r\np =\r\n\r\n    12     4     9     2     6     5     8     3    10     1\r\n\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_04.png\" alt=\"\"> <p><i>Rotate<\/i>, counter clockwise.<\/p><pre class=\"codeinput\">   p = p([3:10 1:2])\r\n   observatory(p)\r\n   snapnow\r\n<\/pre><pre class=\"codeoutput\">\r\np =\r\n\r\n     9     2     6     5     8     3    10     1    12     4\r\n\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_05.png\" alt=\"\"> <p><i>Invert<\/i>, interchange interior with exterior.<\/p><pre class=\"codeinput\">   p = p([6:10 1:5])\r\n   observatory(p)\r\n   snapnow\r\n<\/pre><pre class=\"codeoutput\">\r\np =\r\n\r\n     3    10     1    12     4     9     2     6     5     8\r\n\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_06.png\" alt=\"\"> <p>Applying two reflections, five rotations, and two inversions to each of the original six solutions produces a grand total of <tt>6*2*5*2 = 120<\/tt> different magic stars.<\/p><h4>More five-point stars<a name=\"26be6765-7a94-4806-a09e-652c1b42083b\"><\/a><\/h4><p>You can modify my code to leave out the 2 instead of the 7. Use <tt>v = [1 3:10]<\/tt> instead of <tt>v = [1:6 8:10]<\/tt>. You will find that the search for solutions comes up empty. Magic stars formed from the integers 1 through 12 without the 2 and 11 do not exist.<\/p><p>You can also try including 11, but leaving out 2 and 6. Use <tt>v = [1 3:5 7:11]<\/tt> instead of <tt>v = [1:6 8:10]<\/tt>. Is there an isomorphism between these stars and we ones I described above?<\/p><h4>Six-point<a name=\"f618ad8f-c450-4c6c-b118-5d71f5cee7e8\"><\/a><\/h4><p>We can make a 6-point star using the integers from 1 to 12, so we don't have to bend the rules.  But I am going to restrict the search space and be more careful about memory usage.<\/p><p>Here is the line sum.<\/p><pre class=\"codeinput\">   clear\r\n   n = 6;\r\n   S = sum(1:2*n);\r\n   L = 2\/n*S\r\n<\/pre><pre class=\"codeoutput\">\r\nL =\r\n\r\n    26\r\n\r\n<\/pre><p>I have decided to restrict the search space to stars with 11 at the apex and 12 at the base.  So I need to find all permutations of the remaining integers from 1 to 10.  This would use ten times as much memory as I needed to do the 5-point star and my laptop can't handle it.  But instead of storing the integers as the MATLAB default eight-byte double precision numbers, I can use one-byte uint8s and reduce the memory requirement by a factor of eight.<\/p><p>Find all permutations of ten integers, stored in single bytes.<\/p><pre class=\"codeinput\">   v = uint8(1:10);\r\n   P = perms(v);\r\n<\/pre><p>Insert a column of 11s and a column of 12s in the appropriate places.<\/p><pre class=\"codeinput\">   c = ones(size(P,1),1,<span class=\"string\">'uint8'<\/span>);\r\n   P = [11*c P(:,1:5) 12*c P(:,6:10)];\r\n   clear <span class=\"string\">c<\/span>\r\n<\/pre><p>The matrix has 10! rows, which is about 3.6 million.<\/p><pre class=\"codeinput\">   sizeP = size(P)\r\n<\/pre><pre class=\"codeoutput\">\r\nsizeP =\r\n\r\n     3628800          12\r\n\r\n<\/pre><p>But the storage required is not much more than above.<\/p><pre class=\"codeinput\">   whos\r\n<\/pre><pre class=\"codeoutput\">  Name             Size               Bytes  Class     Attributes\r\n\r\n  L                1x1                    8  double              \r\n  P          3628800x12            43545600  uint8               \r\n  S                1x1                    8  double              \r\n  n                1x1                    8  double              \r\n  sizeP            1x2                   16  double              \r\n  v                1x10                  10  uint8               \r\n\r\n<\/pre><p>There are six line equations to be satisfied.<\/p><pre class=\"codeinput\">   f = find(P(:,1)+P(:,2)+P(:,4)+P(:,5) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,3)+P(:,4)+P(:,6)+P(:,7) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,5)+P(:,6)+P(:,8)+P(:,9) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,7)+P(:,8)+P(:,10)+P(:,11) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,9)+P(:,10)+P(:,12)+P(:,1) == L &amp; <span class=\"keyword\">...<\/span>\r\n            P(:,11)+P(:,12)+P(:,2)+P(:,3) == L)\r\n<\/pre><pre class=\"codeoutput\">\r\nf =\r\n\r\n      235278\r\n      520708\r\n      641908\r\n     1321733\r\n     1522350\r\n     1930425\r\n     2012865\r\n     2613900\r\n\r\n<\/pre><p>Here are the eight solutions found in the 3.6 million rows. Again, the last four are reversals of the first four.<\/p><pre class=\"codeinput\">   P = P(f,:)\r\n<\/pre><pre class=\"codeoutput\">\r\nP =\r\n\r\n   11   10    4    2    3    8   12    6    9    1    7    5\r\n   11    9    6    1    5    7   12    4   10    2    8    3\r\n   11    9    3    1    5   10   12    4    7    2    8    6\r\n   11    7    4    2    6    8   12    3    9    1   10    5\r\n   11    6    8    2    7    4   12   10    5    1    3    9\r\n   11    5    7    1    9    6   12    8    3    2    4   10\r\n   11    5   10    1    9    3   12    8    6    2    4    7\r\n   11    3    8    2   10    4   12    7    5    1    6    9\r\n\r\n<\/pre><p>I think the first one is quite attractive. I have not investigated all the possible symmetries and transformations.<\/p><pre class=\"codeinput\">   observatory(P(1,:))\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_07.png\" alt=\"\"> <h4>Further reading<a name=\"1d8fe3eb-beef-4cfe-8503-3f6e8dab829c\"><\/a><\/h4><p>Marian Trenkler, <i>Magic Stars<\/i>, PME Journal 11, 2004, 549-554<\/p><p>Harvey Heinz, Magic Stars Index Page, <a title=\"http:\/\/www.magic-squares.net\/magic_stars_index.htm (link no longer works)\">&lt;http:\/\/www.magic-squares.net\/magic_stars_index.htm<\/a>&gt;<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_cc5e02ff9483480da36ae7a95bbf1c8a() {\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='cc5e02ff9483480da36ae7a95bbf1c8a ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' cc5e02ff9483480da36ae7a95bbf1c8a';\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        copyright = 'Copyright 2014 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_cc5e02ff9483480da36ae7a95bbf1c8a()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2014a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2014a<br><\/p><\/div><!--\r\ncc5e02ff9483480da36ae7a95bbf1c8a ##### SOURCE BEGIN #####\r\n%% Magic Stars\r\n% Magic Stars are a little like Magic Squares.  My grandson was introduced\r\n% to them in his junior high school math class.\r\n\r\n%% Family Enterprise\r\n% This post is a family enterprise.  My grandson Ben heard about\r\n% five-point magic stars in his junior high school math class, where they\r\n% tackled them by hand.  Ben told his mom Kam, my daughter, who wrote a\r\n% MATLAB program, and then told me.\r\n\r\n%% Observatory\r\n% Here is the function that I use to view the stars.\r\n\r\n   type observatory\r\n\r\n%% Basic Stars\r\n% There are lots of kinds of magic stars.  Here are the most basic.\r\n% Draw a regular _n_-point star the way you learned to draw a 5-point star.\r\n% Connect the _n_ points evenly spaced around a circle by _n_ lines\r\n% between alternate points.  This produces a regular _n_-gon in the interior.\r\n% The vertices of the outer points, together with the vertices of the\r\n% interior polygon, gives you _2n_ points.  Here are the five and six point\r\n% stars, with the points numbered in consecutive clockwise order.\r\n\r\n   observatory(1:10)\r\n   snapnow\r\n\r\n   observatory(1:12)\r\n\r\n%% Magic Stars\r\n% To turn one of these stars into a magic star, you need to rearrange the\r\n% numbers so that the sums along each of the _n_ lines are equal, just\r\n% like the sums along the rows and columns in a magic square.  It turns out\r\n% that this is impossible for the 5-point star and we will have to modify\r\n% the rules.  But it is possible for the 6-point star.\r\n\r\n%% Five-point\r\n% The sum of the integers from 1 to 10 is _S = 55_.  There are five lines in\r\n% the 5-point star and each integer is involved in the intersection of two of\r\n% these lines, so if the sums along each line are to be equal, that sum must\r\n% be _L = (2\/5)S = 22_.  We are seeking a permutation _p_ of the first ten\r\n% integers that satisfies the five equations.\r\n%\r\n% $$ p_1+p_2+p_4+p_5 = L $$\r\n%\r\n% $$ p_3+p_4+p_6+p_7 = L $$\r\n%\r\n% $$ p_5+p_6+p_8+p_9 = L $$\r\n%\r\n% $$ p_7+p_8+p_{10}+p_1 = L $$\r\n%\r\n% $$ p_9+p_{10}+p_2+p_3 = L $$\r\n%\r\n% The subscripts in each of these equations can be read off by following\r\n% one of the lines across the star.\r\n\r\n%%\r\n% An exhaustive search of all 10! permutations of the integers 1 through 10\r\n% reveals that there are no solutions to these equations, so no perfect\r\n% five-point magic star exists.\r\n\r\n%%\r\n% But do not despair.  Relax the rules by allowing more players. Ben's class\r\n% was given the challenge of finding a magic 5-point star using nine of the\r\n% ten integers between 1 and 10, and also using 12.  They had to be careful.\r\n% The sum _S_ needs to be a multiple of 5 because the line sum is always\r\n% going to be _L = (2\/5)S_.  So they learned that they had to exclude either\r\n% 2 or 7.  Let's first try leaving out the 7.\r\n\r\n%%\r\n% I'm going to give the integer 12 a special role by fixing it at the apex\r\n% of the star.  This eliminates all the stars that are obtained from the ones\r\n% that I will find by simple rotations, and it also eliminates all the stars\r\n% where 12 is at an internal point.  It leaves only nine integers left to\r\n% permute.  Here are the parameters.\r\n\r\n   clear\r\n   n = 5;\r\n   v = [1:6 8:10];   % Omit 7.\r\n   S = sum(v) + 12\r\n   L = 2\/n*S\r\n\r\n%%\r\n% Use the MATLAB function |perms| to generate all possible permutations\r\n% of the nine free integers.\r\n\r\n   P = perms(v);\r\n\r\n%%\r\n% Insert a column of 12's in front to produce a matrix with 9!\r\n% (that's 9 factorial) rows and 10 columns.\r\n\r\n   P = [12*ones(size(P,1),1) P];\r\n   sizeP = size(P)\r\n\r\n%% \r\n% See how much storage we're using.\r\n\r\n   whos\r\n\r\n%%\r\n% My laptop can handle 29 megabytes.\r\n   \r\n%%\r\n% We are ready to search for the solutions.\r\n\r\n   f = find(P(:,1)+P(:,2)+P(:,4)+P(:,5) == L & ...\r\n            P(:,3)+P(:,4)+P(:,6)+P(:,7) == L & ...\r\n            P(:,5)+P(:,6)+P(:,8)+P(:,9) == L & ...\r\n            P(:,7)+P(:,8)+P(:,10)+P(:,1) == L & ...\r\n            P(:,9)+P(:,10)+P(:,2)+P(:,3) == L)\r\n\r\n%%\r\n% Out of the over one-third of a million permutations, these are the indices\r\n% that satisfy the five line equations.  Here are those solutions.\r\n\r\n   P = P(f,:)\r\n\r\n%%\r\n% Twelve solutions were found. The last solution has the integers\r\n% from 1 to 5 in the interior.\r\n\r\n   p = P(12,:)\r\n   observatory(p)\r\n\r\n%% Rotations and reflections\r\n% Our search for stars formed from the integers from 1 to 12, leaving out\r\n% 7 and 11, found 12 solutions.  But the last six are actually reflections of\r\n% the first six.  Look at the solution array P, and ignore the first column\r\n% with the 12s.  If you read the last six rows backwards, from right to left,\r\n% you will get the first six rows in a different order.\r\n% You can also think of this as clockwise versus counter clockwise indexing.\r\n\r\n%%\r\n% So, we have found six distinctly different solutions with 12 at the apex.\r\n% There are three kinds of transformations that can be made on these\r\n% solutions.  This will produce all of the possible magic stars that can\r\n% be made from this set of integers.\r\n\r\n%%\r\n% _Reflect_, about the vertical axis.\r\n\r\n   p = p([1 10:-1:2])\r\n   observatory(p)\r\n   snapnow\r\n\r\n%%\r\n% _Rotate_, counter clockwise.\r\n\r\n   p = p([3:10 1:2])\r\n   observatory(p)\r\n   snapnow\r\n\r\n%%\r\n% _Invert_, interchange interior with exterior.\r\n\r\n   p = p([6:10 1:5])\r\n   observatory(p)\r\n   snapnow\r\n\r\n%%\r\n% Applying two reflections, five rotations, and two inversions to each\r\n% of the original six solutions produces a grand total of |6*2*5*2 = 120|\r\n% different magic stars.\r\n\r\n%% More five-point stars\r\n% You can modify my code to leave out the 2 instead of the 7.\r\n% Use |v = [1 3:10]| instead of |v = [1:6 8:10]|.\r\n% You will find that the search for solutions comes up empty.\r\n% Magic stars formed from the integers 1 through 12 without the 2 and 11 do\r\n% not exist.\r\n\r\n%%\r\n% You can also try including 11, but leaving out 2 and 6.\r\n% Use |v = [1 3:5 7:11]| instead of |v = [1:6 8:10]|.\r\n% Is there an isomorphism between these stars and we ones I described above?\r\n\r\n%% Six-point\r\n% We can make a 6-point star using the integers from 1 to 12, so we don't\r\n% have to bend the rules.  But I am going to restrict the search space and\r\n% be more careful about memory usage.\r\n\r\n%%\r\n% Here is the line sum.\r\n\r\n   clear\r\n   n = 6;\r\n   S = sum(1:2*n);\r\n   L = 2\/n*S\r\n\r\n%%\r\n% I have decided to restrict the search space to stars with 11 at the apex\r\n% and 12 at the base.  So I need to find all permutations of the remaining\r\n% integers from 1 to 10.  This would use ten times as much memory as\r\n% I needed to do the 5-point star and my laptop can't handle it.  But instead\r\n% of storing the integers as the MATLAB default eight-byte double\r\n% precision numbers, I can use one-byte uint8s and reduce the memory\r\n% requirement by a factor of eight.\r\n\r\n%%\r\n% Find all permutations of ten integers, stored in single bytes.\r\n\r\n   v = uint8(1:10);\r\n   P = perms(v);\r\n\r\n%%\r\n% Insert a column of 11s and a column of 12s in the appropriate places.\r\n\r\n   c = ones(size(P,1),1,'uint8');\r\n   P = [11*c P(:,1:5) 12*c P(:,6:10)]; \r\n   clear c\r\n\r\n%%\r\n% The matrix has 10! rows, which is about 3.6 million.\r\n\r\n   sizeP = size(P)\r\n\r\n%%\r\n% But the storage required is not much more than above.\r\n\r\n   whos\r\n\r\n%%\r\n% There are six line equations to be satisfied.\r\n\r\n   f = find(P(:,1)+P(:,2)+P(:,4)+P(:,5) == L & ...\r\n            P(:,3)+P(:,4)+P(:,6)+P(:,7) == L & ...\r\n            P(:,5)+P(:,6)+P(:,8)+P(:,9) == L & ...\r\n            P(:,7)+P(:,8)+P(:,10)+P(:,11) == L & ...\r\n            P(:,9)+P(:,10)+P(:,12)+P(:,1) == L & ...\r\n            P(:,11)+P(:,12)+P(:,2)+P(:,3) == L)\r\n\r\n%%\r\n% Here are the eight solutions found in the 3.6 million rows.\r\n% Again, the last four are reversals of the first four.\r\n\r\n   P = P(f,:)\r\n\r\n%%\r\n% I think the first one is quite attractive.\r\n% I have not investigated all the possible symmetries and transformations.\r\n\r\n   observatory(P(1,:))\r\n\r\n%% Further reading\r\n% Marian Trenkler, _Magic Stars_, PME Journal 11, 2004, 549-554,\r\n% <http:\/\/math.ku.sk\/~trenkler\/MagicStars.doc\r\n% http:\/\/math.ku.sk\/~trenkler\/MagicStars.doc>\r\n\r\n%%\r\n% Harvey Heinz, Magic Stars Index Page,\r\n% <http:\/\/www.magic-squares.net\/magic_stars_index.htm\r\n% http:\/\/www.magic-squares.net\/magic_stars_index.htm>\r\n\r\n\r\n\r\n##### SOURCE END ##### cc5e02ff9483480da36ae7a95bbf1c8a\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/star_blog_01.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Magic Stars are a little like Magic Squares.  My grandson was introduced to them in his junior high school math class.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2014\/01\/20\/magic-stars\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,9],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/875"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=875"}],"version-history":[{"count":22,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/875\/revisions"}],"predecessor-version":[{"id":1821,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/875\/revisions\/1821"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}