{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":1673,"title":"Pandiagonal Prime Magic Square Verification","description":"Verify if an NxN matrix is a Pandiagonal Prime Magic Square.  \r\n\r\nRequired properties:\r\n\r\n  1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n  2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\r\n\r\n*Input:* M  (Matrix NxN)\r\n\r\n*Output:* Magic Constant ( 0 if invalid )\r\n\r\n*Example:*\r\n\r\nm=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\r\n\r\nRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31; \r\n\r\nAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\r\n\r\n*Related:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function Kurchan Evaluation\u003e has similar array processing\r\n\r\n2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14","description_html":"\u003cp\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/p\u003e\u003cp\u003eRequired properties:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M  (Matrix NxN)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Magic Constant ( 0 if invalid )\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/p\u003e\u003cp\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/p\u003e\u003cp\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\"\u003eKurchan Evaluation\u003c/a\u003e has similar array processing\u003c/p\u003e\u003cp\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\u003c/p\u003e","function_template":"function MagicConstant = pandiag(m)\r\n MagicConstant=1;\r\nend\r\n","test_suite":"%%\r\nm=magic(20);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=[41 137 149 19 37 6427 6343 6277 6449 6353 131 211 397 281 431 6421 6329 6197 6271 6199\r\n557 29 367 59 173 5923 6121 6101 6163 6287 643 827 929 947 769 5897 6043 5623 5851 5791\r\n419 571 631 853 919 6053 5801 5783 5573 5387 859 1229 857 1201 1487 5689 5419 5749 5393 5227\r\n1061 1103 1231 661 1093 5323 5381 5231 5189 5273 1847 2293 1499 2281 1867 4789 4243 5059 4889 4787\r\n1249 1277 1423 1889 1997 5051 4951 4931 4241 4373 2239 2309 2069 2731 2377 4481 4483 4597 4159 4273\r\n241 337 607 683 773 6311 6203 5987 5869 5857 151 263 359 421 379 6317 6217 6067 6047 6011\r\n1039 1301 1553 1697 1759 5501 5569 4999 5101 4801 953 503 991 809 1163 5527 5647 5477 5413 5297\r\n1471 2087 2003 1871 2357 5077 4561 4603 4723 4357 1031 1429 1777 1523 1789 5441 4943 4637 4903 4517\r\n2647 3823 2381 3709 3593 3989 2713 4177 3461 3061 1861 2633 2113 2089 2819 4523 3851 4349 3761 3547\r\n3373 3253 3323 3583 3259 3347 3539 3343 3307 3391 2383 2221 2677 2741 2879 3917 4007 3677 3389 3491\r\n6379 6299 6113 6229 6079 89 181 313 239 311 6469 6373 6361 6491 6473 83 167 233 61 157\r\n5867 5683 5581 5563 5741 613 467 887 659 719 5953 6481 6143 6451 6337 587 389 409 347 223\r\n5651 5281 5653 5309 5023 821 1091 761 1117 1283 6091 5939 5879 5657 5591 457 709 727 937 1123\r\n4663 4217 5011 4229 4643 1721 2267 1451 1621 1723 5449 5407 5279 5849 5417 1187 1129 1279 1321 1237\r\n4271 4201 4441 3779 4133 2029 2027 1913 2351 2237 5261 5233 5087 4621 4513 1459 1559 1579 2269 2137\r\n6359 6247 6151 6089 6131 193 293 443 463 499 6269 6173 5903 5827 5737 199 307 523 641 653\r\n5557 6007 5519 5701 5347 983 863 1033 1097 1213 5471 5209 4957 4813 4751 1009 941 1511 1409 1709\r\n5479 5081 4733 4987 4721 1069 1567 1873 1607 1993 5039 4423 4507 4639 4153 1433 1949 1907 1787 2153\r\n4649 3877 4397 4421 3691 1987 2659 2161 2749 2963 3863 2687 4129 2801 2917 2521 3797 2333 3049 3449\r\n4127 4289 3833 3769 3631 2593 2503 2833 3121 3019 3137 3257 3187 2927 3251 3163 2971 3167 3203 3119];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,65100))\r\n%%\r\nm=[5 73 127 137 53\r\n37 167 17 71 103\r\n83 101 13 67 131\r\n43 31 197 113 11\r\n227 23 41 7 97];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,395))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t563\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,1597))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t3\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=magic(7);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-22T04:21:02.000Z","updated_at":"2026-03-02T16:07:10.000Z","published_at":"2013-06-22T06:02:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRequired properties:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1) N^2 prime values ( No repeats, 1 is a non-prime )\\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\\n3) Magic Constant is the sum of a row/column/diagonal]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M (Matrix NxN)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Magic Constant ( 0 if invalid )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKurchan Evaluation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e has similar array processing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1697,"title":"Make a Pandiagonal Prime Magic Square: 11 x 11","description":"This Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\r\n\r\n\r\nAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\r\n\r\nA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\r\n\r\n*Input:* APk matrix (11,11)\r\n\r\n*Output:* Pandiagonal Matrix (11,11) \r\n\r\n*Algorithm:*\r\n\r\nThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\r\n\r\n  Detailed Methodolgy:\r\n  1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n  2) First column of PS will be first column of P\r\n  3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n  4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\r\n*Related Challenges:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification Pandiagonal Check\u003e\r\n\r\n2) Find 11x11 Pandiagonal 18191 APk set\r\n\r\n*Restrictions: No str2num or regexp (enforced as necessary)*  ","description_html":"\u003cp\u003eThis Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/p\u003e\u003cp\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\u003c/p\u003e\u003cp\u003eA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e APk matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Pandiagonal Matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eAlgorithm:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eDetailed Methodolgy:\r\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n2) First column of PS will be first column of P\r\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\"\u003ePandiagonal Check\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/p\u003e\u003cp\u003e\u003cb\u003eRestrictions: No str2num or regexp (enforced as necessary)\u003c/b\u003e\u003c/p\u003e","function_template":"function p = Pandiagonal_11(APk)\r\n  p=APk;\r\nend","test_suite":"%%\r\nAPk= [59 101 271 509 577 1291 1699 1877 2357 2999 3307 \r\n311 353 523 761 829 1543 1951 2129 2609 3251 3559 \r\n389 431 601 839 907 1621 2029 2207 2687 3329 3637 \r\n521 563 733 971 1039 1753 2161 2339 2819 3461 3769 \r\n599 641 811 1049 1117 1831 2239 2417 2897 3539 3847 \r\n911 953 1123 1361 1429 2143 2551 2729 3209 3851 4159 \r\n1109 1151 1321 1559 1627 2341 2749 2927 3407 4049 4357 \r\n1481 1523 1693 1931 1999 2713 3121 3299 3779 4421 4729 \r\n2099 2141 2311 2549 2617 3331 3739 3917 4397 5039 5347 \r\n2591 2633 2803 3041 3109 3823 4231 4409 4889 5531 5839 \r\n3371 3413 3583 3821 3889 4603 5011 5189 5669 6311 6619];\r\np = Pandiagonal_11(APk);\r\nassert(all(unique(p(:))==unique(APk(:))))\r\nrcs=sum([p p']);\r\nassert(all(rcs==trace(APk)))\r\n\r\npd=p;\r\npad=p;\r\nfor i=2:11\r\n pd(i,:)=circshift(p(i,:),[0 -i+1]);\r\n pad(i,:)=circshift(p(i,:),[0 i-1]);\r\nend\r\n\r\nrd=sum([pd pad]);\r\nassert(all(rd==trace(APk)))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2013-07-09T19:42:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-05T21:43:45.000Z","updated_at":"2025-12-04T05:22:24.000Z","published_at":"2013-07-05T22:55:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u0026gt;offset(i), j\u0026gt;i.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e APk matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Pandiagonal Matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eAlgorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value. The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Detailed Methodolgy:\\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\\n2) First column of PS will be first column of P\\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePandiagonal Check\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRestrictions: No str2num or regexp (enforced as necessary)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":1673,"title":"Pandiagonal Prime Magic Square Verification","description":"Verify if an NxN matrix is a Pandiagonal Prime Magic Square.  \r\n\r\nRequired properties:\r\n\r\n  1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n  2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\r\n\r\n*Input:* M  (Matrix NxN)\r\n\r\n*Output:* Magic Constant ( 0 if invalid )\r\n\r\n*Example:*\r\n\r\nm=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\r\n\r\nRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31; \r\n\r\nAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\r\n\r\n*Related:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function Kurchan Evaluation\u003e has similar array processing\r\n\r\n2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14","description_html":"\u003cp\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/p\u003e\u003cp\u003eRequired properties:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M  (Matrix NxN)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Magic Constant ( 0 if invalid )\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/p\u003e\u003cp\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/p\u003e\u003cp\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\"\u003eKurchan Evaluation\u003c/a\u003e has similar array processing\u003c/p\u003e\u003cp\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\u003c/p\u003e","function_template":"function MagicConstant = pandiag(m)\r\n MagicConstant=1;\r\nend\r\n","test_suite":"%%\r\nm=magic(20);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=[41 137 149 19 37 6427 6343 6277 6449 6353 131 211 397 281 431 6421 6329 6197 6271 6199\r\n557 29 367 59 173 5923 6121 6101 6163 6287 643 827 929 947 769 5897 6043 5623 5851 5791\r\n419 571 631 853 919 6053 5801 5783 5573 5387 859 1229 857 1201 1487 5689 5419 5749 5393 5227\r\n1061 1103 1231 661 1093 5323 5381 5231 5189 5273 1847 2293 1499 2281 1867 4789 4243 5059 4889 4787\r\n1249 1277 1423 1889 1997 5051 4951 4931 4241 4373 2239 2309 2069 2731 2377 4481 4483 4597 4159 4273\r\n241 337 607 683 773 6311 6203 5987 5869 5857 151 263 359 421 379 6317 6217 6067 6047 6011\r\n1039 1301 1553 1697 1759 5501 5569 4999 5101 4801 953 503 991 809 1163 5527 5647 5477 5413 5297\r\n1471 2087 2003 1871 2357 5077 4561 4603 4723 4357 1031 1429 1777 1523 1789 5441 4943 4637 4903 4517\r\n2647 3823 2381 3709 3593 3989 2713 4177 3461 3061 1861 2633 2113 2089 2819 4523 3851 4349 3761 3547\r\n3373 3253 3323 3583 3259 3347 3539 3343 3307 3391 2383 2221 2677 2741 2879 3917 4007 3677 3389 3491\r\n6379 6299 6113 6229 6079 89 181 313 239 311 6469 6373 6361 6491 6473 83 167 233 61 157\r\n5867 5683 5581 5563 5741 613 467 887 659 719 5953 6481 6143 6451 6337 587 389 409 347 223\r\n5651 5281 5653 5309 5023 821 1091 761 1117 1283 6091 5939 5879 5657 5591 457 709 727 937 1123\r\n4663 4217 5011 4229 4643 1721 2267 1451 1621 1723 5449 5407 5279 5849 5417 1187 1129 1279 1321 1237\r\n4271 4201 4441 3779 4133 2029 2027 1913 2351 2237 5261 5233 5087 4621 4513 1459 1559 1579 2269 2137\r\n6359 6247 6151 6089 6131 193 293 443 463 499 6269 6173 5903 5827 5737 199 307 523 641 653\r\n5557 6007 5519 5701 5347 983 863 1033 1097 1213 5471 5209 4957 4813 4751 1009 941 1511 1409 1709\r\n5479 5081 4733 4987 4721 1069 1567 1873 1607 1993 5039 4423 4507 4639 4153 1433 1949 1907 1787 2153\r\n4649 3877 4397 4421 3691 1987 2659 2161 2749 2963 3863 2687 4129 2801 2917 2521 3797 2333 3049 3449\r\n4127 4289 3833 3769 3631 2593 2503 2833 3121 3019 3137 3257 3187 2927 3251 3163 2971 3167 3203 3119];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,65100))\r\n%%\r\nm=[5 73 127 137 53\r\n37 167 17 71 103\r\n83 101 13 67 131\r\n43 31 197 113 11\r\n227 23 41 7 97];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,395))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t563\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,1597))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t3\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=magic(7);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-22T04:21:02.000Z","updated_at":"2026-03-02T16:07:10.000Z","published_at":"2013-06-22T06:02:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRequired properties:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1) N^2 prime values ( No repeats, 1 is a non-prime )\\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\\n3) Magic Constant is the sum of a row/column/diagonal]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M (Matrix NxN)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Magic Constant ( 0 if invalid )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKurchan Evaluation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e has similar array processing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1697,"title":"Make a Pandiagonal Prime Magic Square: 11 x 11","description":"This Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\r\n\r\n\r\nAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\r\n\r\nA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\r\n\r\n*Input:* APk matrix (11,11)\r\n\r\n*Output:* Pandiagonal Matrix (11,11) \r\n\r\n*Algorithm:*\r\n\r\nThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\r\n\r\n  Detailed Methodolgy:\r\n  1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n  2) First column of PS will be first column of P\r\n  3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n  4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\r\n*Related Challenges:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification Pandiagonal Check\u003e\r\n\r\n2) Find 11x11 Pandiagonal 18191 APk set\r\n\r\n*Restrictions: No str2num or regexp (enforced as necessary)*  ","description_html":"\u003cp\u003eThis Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/p\u003e\u003cp\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\u003c/p\u003e\u003cp\u003eA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e APk matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Pandiagonal Matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eAlgorithm:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eDetailed Methodolgy:\r\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n2) First column of PS will be first column of P\r\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\"\u003ePandiagonal Check\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/p\u003e\u003cp\u003e\u003cb\u003eRestrictions: No str2num or regexp (enforced as necessary)\u003c/b\u003e\u003c/p\u003e","function_template":"function p = Pandiagonal_11(APk)\r\n  p=APk;\r\nend","test_suite":"%%\r\nAPk= [59 101 271 509 577 1291 1699 1877 2357 2999 3307 \r\n311 353 523 761 829 1543 1951 2129 2609 3251 3559 \r\n389 431 601 839 907 1621 2029 2207 2687 3329 3637 \r\n521 563 733 971 1039 1753 2161 2339 2819 3461 3769 \r\n599 641 811 1049 1117 1831 2239 2417 2897 3539 3847 \r\n911 953 1123 1361 1429 2143 2551 2729 3209 3851 4159 \r\n1109 1151 1321 1559 1627 2341 2749 2927 3407 4049 4357 \r\n1481 1523 1693 1931 1999 2713 3121 3299 3779 4421 4729 \r\n2099 2141 2311 2549 2617 3331 3739 3917 4397 5039 5347 \r\n2591 2633 2803 3041 3109 3823 4231 4409 4889 5531 5839 \r\n3371 3413 3583 3821 3889 4603 5011 5189 5669 6311 6619];\r\np = Pandiagonal_11(APk);\r\nassert(all(unique(p(:))==unique(APk(:))))\r\nrcs=sum([p p']);\r\nassert(all(rcs==trace(APk)))\r\n\r\npd=p;\r\npad=p;\r\nfor i=2:11\r\n pd(i,:)=circshift(p(i,:),[0 -i+1]);\r\n pad(i,:)=circshift(p(i,:),[0 i-1]);\r\nend\r\n\r\nrd=sum([pd pad]);\r\nassert(all(rd==trace(APk)))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2013-07-09T19:42:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-05T21:43:45.000Z","updated_at":"2025-12-04T05:22:24.000Z","published_at":"2013-07-05T22:55:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u0026gt;offset(i), j\u0026gt;i.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e APk matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Pandiagonal Matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eAlgorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value. The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Detailed Methodolgy:\\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\\n2) First column of PS will be first column of P\\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePandiagonal Check\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRestrictions: No str2num or regexp (enforced as necessary)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"pandiagonal\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"pandiagonal\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"pandiagonal\"","","\"","pandiagonal","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f828a8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fa2b4f82808\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f81f48\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f82b28\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fa2b4f82a88\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fa2b4f829e8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fa2b4f82948\u003e":"tag:\"pandiagonal\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f82948\u003e":"tag:\"pandiagonal\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"pandiagonal\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"pandiagonal\"","","\"","pandiagonal","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f828a8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fa2b4f82808\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f81f48\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f82b28\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fa2b4f82a88\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fa2b4f829e8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fa2b4f82948\u003e":"tag:\"pandiagonal\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fa2b4f82948\u003e":"tag:\"pandiagonal\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1673,"difficulty_rating":"easy"},{"id":1697,"difficulty_rating":"easy-medium"}]}}