{"group":{"group":{"id":71,"name":"Combinatorics III","lockable":false,"created_at":"2018-08-30T15:52:34.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"If these problems involved counting sheep, you'd fall asleep before finishing.","is_default":false,"created_by":26769,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":26,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":492,"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":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf these problems involved counting sheep, you'd fall asleep before finishing.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: normal; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; perspective-origin: 289.5px 10.5px; transform-origin: 289.5px 10.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; white-space: pre-wrap; perspective-origin: 266.5px 10.5px; transform-origin: 266.5px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIf these problems involved counting sheep, you'd fall asleep before finishing.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2019-09-27T20:08:13.000Z"},"current_player":null},"problems":[{"id":44787,"title":"What can you get for exactly amount of money(harder)","description":"Inspired by \"Problem 42996. what can you get for exactly amount of money\"\r\n\u003chttps://ww2.mathworks.cn/matlabcentral/cody/problems/42996-what-can-you-get-for-exactly-amount-of-money\u003e\r\nProblem 42996 is a good problem, but the test suit is too weak.\r\n\r\nYou go to store, where each product has price. Prices are in vector\r\n\r\nv = [ 195 125 260 440 395 290]\r\nand you have amount of money s=570\r\n\r\nQuestion is what can you buy, if you want to use whole amount of money\r\n\r\nFor this data answer is\r\n\r\nres=[ 125 125 125 195]\r\n\r\nThe answer may not be unique, return any feasible answer.\r\nDo not cheat please.\r\n\r\nIn this hard version, \r\n1 \u003c= length(v) \u003c= 50\r\n1 \u003c= s \u003c= 10000000019 (1e10 + 19)\r\n","description_html":"\u003cp\u003eInspired by \"Problem 42996. what can you get for exactly amount of money\" \u003ca href = \"https://ww2.mathworks.cn/matlabcentral/cody/problems/42996-what-can-you-get-for-exactly-amount-of-money\"\u003ehttps://ww2.mathworks.cn/matlabcentral/cody/problems/42996-what-can-you-get-for-exactly-amount-of-money\u003c/a\u003e\r\nProblem 42996 is a good problem, but the test suit is too weak.\u003c/p\u003e\u003cp\u003eYou go to store, where each product has price. Prices are in vector\u003c/p\u003e\u003cp\u003ev = [ 195 125 260 440 395 290]\r\nand you have amount of money s=570\u003c/p\u003e\u003cp\u003eQuestion is what can you buy, if you want to use whole amount of money\u003c/p\u003e\u003cp\u003eFor this data answer is\u003c/p\u003e\u003cp\u003eres=[ 125 125 125 195]\u003c/p\u003e\u003cp\u003eThe answer may not be unique, return any feasible answer.\r\nDo not cheat please.\u003c/p\u003e\u003cp\u003eIn this hard version, \r\n1 \u0026lt;= length(v) \u0026lt;= 50\r\n1 \u0026lt;= s \u0026lt;= 10000000019 (1e10 + 19)\u003c/p\u003e","function_template":"function res = buy(v, s)\r\nres = [1, 2, 3];\r\nend","test_suite":"%%\r\nv = [ 195 125 260 440 395 290];\r\ns = 570;\r\ntic\r\nres = buy(v, s);\r\ntoc\r\nassert(sum(res) == s);\r\nassert(all(ismember(res, v)))\r\n\t\r\n%%\r\nv = [ 150 180 60 40];\r\ns = 210;\r\ntic\r\nres = buy(v, s);\r\ntoc\r\nassert(sum(res) == s);\r\nassert(all(ismember(res, v)))\r\n\r\n%%\r\nv = [ 150 180 60 40];\r\ns = 1e10;\r\ntic\r\nres = buy(v, s);\r\ntoc\r\nassert(sum(res) == s);\r\nassert(all(ismember(res, v)))\r\n\r\n%%\r\nv = [123456, 963852, 753159, 7841, 122];\r\ns = 1e10+19;\r\ntic\r\nres = buy(v, s);\r\ntoc\r\nassert(sum(res) == s);\r\nassert(all(ismember(res, v)))\r\n\r\n%%\r\nv = [319,2770,462,972,8235,6949,3171,9503,345,4388,3816,7656,7952,1869,4898,4456,6464,7094,7547,2761,6798,6551,1627,1190,4984,9598,3404,5853,2239,7513];\r\ns = 1e10+19;\r\ntic;\r\nres = buy(v, s);\r\ntoc;\r\nassert(sum(res) == s);\r\nassert(all(ismember(res, v)))\r\n\r\n%%\r\nv = [3898,2417,4040,965,1320,9421,9562,5753,598,2348,3532,8212,155,431,1690,6492,7318,6478,4510,5471,2964,7447,1890,6868,1836,3685,6257,7803,812,9294,7758,4868,4359,4468,3064,5086,5108,8177,7949,6444,3787,8116,5329,3508,9391,8760,5502,6225,5871,2078];\r\ns = 1e10+19;\r\ntic;\r\nres = buy(v, s);\r\ntoc;\r\nassert(sum(res) == s);\r\nassert(all(ismember(res, v)))","published":true,"deleted":false,"likes_count":3,"comments_count":14,"created_by":8269,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":"2018-11-12T07:09:17.000Z","rescore_all_solutions":false,"group_id":71,"created_at":"2018-11-12T06:38:43.000Z","updated_at":"2025-12-14T23:03:12.000Z","published_at":"2018-11-12T06:39:22.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\u003eInspired by \\\"Problem 42996. what can you get for exactly amount of money\\\"\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=\\\"https://ww2.mathworks.cn/matlabcentral/cody/problems/42996-what-can-you-get-for-exactly-amount-of-money\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://ww2.mathworks.cn/matlabcentral/cody/problems/42996-what-can-you-get-for-exactly-amount-of-money\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; Problem 42996 is a good problem, but the test suit is too weak.\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\u003eYou go to store, where each product has price. Prices are in vector\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\u003ev = [ 195 125 260 440 395 290] and you have amount of money s=570\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\u003eQuestion is what can you buy, if you want to use whole amount of money\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\u003eFor this data answer is\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\u003eres=[ 125 125 125 195]\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 answer may not be unique, return any feasible answer. Do not cheat please.\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\u003eIn this hard version, 1 \u0026lt;= length(v) \u0026lt;= 50 1 \u0026lt;= s \u0026lt;= 10000000019 (1e10 + 19)\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":44782,"title":"Highest powers in factorials","description":"This is the inverse of the problem \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44747 Exponents in Factorials\u003e.  Instead of being given a number and finding out the highest exponent it can be raised to for a given factorial, you'll be given a power, and you're being asked to find the highest number that can be raised to that power for a given factorial.\r\n\r\nFor example, n=7 and p=2.  The highest perfect square (p=2) that can evenly divide 5040 (n=7, and 7!=5040) is 144, or 12^2.  Therefore, your output should be y=12.\r\n\r\nAs before, you can assume that both n and power are integers greater than 1.","description_html":"\u003cp\u003eThis is the inverse of the problem \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44747\"\u003eExponents in Factorials\u003c/a\u003e.  Instead of being given a number and finding out the highest exponent it can be raised to for a given factorial, you'll be given a power, and you're being asked to find the highest number that can be raised to that power for a given factorial.\u003c/p\u003e\u003cp\u003eFor example, n=7 and p=2.  The highest perfect square (p=2) that can evenly divide 5040 (n=7, and 7!=5040) is 144, or 12^2.  Therefore, your output should be y=12.\u003c/p\u003e\u003cp\u003eAs before, you can assume that both n and power are integers greater than 1.\u003c/p\u003e","function_template":"function y = biggest_power(n,p)\r\n  y = n*p;\r\nend","test_suite":"%%\r\nn=7;p=2;y=biggest_power(n,p)\r\nassert(isequal(y,12));\r\n%%\r\nn=30;p=4;y=biggest_power(n,p)\r\nassert(isequal(y,60480));\r\n%%\r\nn=25;p=11;y=biggest_power(n,p)\r\nassert(isequal(y,4));\r\n%%\r\nn=1000;p=100;y=biggest_power(n,p)\r\nassert(isequal(y,7257600));\r\n%%\r\ns=0;\r\np=10;\r\nfor n=100:-1:20\r\n    s(n-19)=biggest_power(n,p);\r\nend\r\nassert(isequal(sum(s),79641800));\r\nassert(isequal(numel(unique(s)),13));\r\nassert(isequal(floor(mean(s)),983232));\r\n%%\r\nn=100;\r\ns=0;\r\nfor p=30:-1:10\r\n    s(p-9)=biggest_power(n,p);\r\nend\r\nassert(isequal(sum(s),14825664));\r\nassert(isequal(numel(unique(s)),7));\r\nassert(isequal(floor(mean(s)),705984));\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":71,"created_at":"2018-11-08T14:45:39.000Z","updated_at":"2025-12-14T23:05:05.000Z","published_at":"2018-11-08T14:45:39.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 is the inverse of the problem\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44747\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExponents in Factorials\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Instead of being given a number and finding out the highest exponent it can be raised to for a given factorial, you'll be given a power, and you're being asked to find the highest number that can be raised to that power for a given factorial.\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\u003eFor example, n=7 and p=2. The highest perfect square (p=2) that can evenly divide 5040 (n=7, and 7!=5040) is 144, or 12^2. Therefore, your output should be y=12.\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\u003eAs before, you can assume that both n and power are integers greater than 1.\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":44747,"title":"Exponents in Factorials","description":"It's time to get excited about numbers!!!  Well, we're just dealing with factorials here, but it's still a good reason to get excited.  You're given two numbers, n and k.  Calculate the highest exponent of k that could appear in n!\r\n\r\nFor example, for n=5 and k=2, you're looking for the highest exponent of 2 that could appear in 5!, or 120.  The highest power of 2 that evenly divides 120 is 3 (2^3 evenly divides 120, while 2^4 does not) so your output for maxexp(5,2)=3.\r\n\r\nYou can assume that both n and k are both integers greater than 1.\r\n","description_html":"\u003cp\u003eIt's time to get excited about numbers!!!  Well, we're just dealing with factorials here, but it's still a good reason to get excited.  You're given two numbers, n and k.  Calculate the highest exponent of k that could appear in n!\u003c/p\u003e\u003cp\u003eFor example, for n=5 and k=2, you're looking for the highest exponent of 2 that could appear in 5!, or 120.  The highest power of 2 that evenly divides 120 is 3 (2^3 evenly divides 120, while 2^4 does not) so your output for maxexp(5,2)=3.\u003c/p\u003e\u003cp\u003eYou can assume that both n and k are both integers greater than 1.\u003c/p\u003e","function_template":"function y = maxexp(n,k)\r\n\r\n% Maximum exponent of k that can be found in n!\r\n\r\n  y = n-k;\r\nend","test_suite":"%%\r\nassert(isequal(maxexp(5,2),3))\r\n%%\r\nassert(isequal(maxexp(9,3),4))\r\n%%\r\nassert(isequal(maxexp(10,14),1))\r\n%%\r\nq=arrayfun(@(x) maxexp(x,13),2:12);\r\nassert(all(q==0))\r\n%%\r\nassert(isequal(maxexp(67,2),64))\r\n%%\r\nassert(isequal(maxexp(10,4),4))\r\n%%\r\ns1=maxexp(100,3);\r\ns2=maxexp(200,5);\r\nassert(isequal(maxexp(s2,s1)-maxexp(s1,s2),maxexp(100,13)+1))\r\n%%\r\nv=zeros(1,99);\r\nfor a=2:100\r\n    v(a-1)=maxexp(100,a);\r\nend\r\nassert(isequal(sum(v==1),10))\r\nassert(isequal(sum(find(v==2)),496))\r\nassert(isequal(sum(v),1299))\r\nassert(isequal(max(v)-min(v),96))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":71,"created_at":"2018-10-22T17:29:48.000Z","updated_at":"2025-12-14T23:07:11.000Z","published_at":"2018-10-22T17:29:48.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eIt's time to get excited about numbers!!! Well, we're just dealing with factorials here, but it's still a good reason to get excited. You're given two numbers, n and k. Calculate the highest exponent of k that could appear in n!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, for n=5 and k=2, you're looking for the highest exponent of 2 that could appear in 5!, or 120. The highest power of 2 that evenly divides 120 is 3 (2^3 evenly divides 120, while 2^4 does not) so your output for maxexp(5,2)=3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume that both n and k are both integers greater than 1.\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":1634,"title":"Kurchan Square - Evaluation Function","description":"Evaluate a Kurchan square. An NxN square with values 1:N^2.\r\n\r\nGiven a square matrix determine the products of each row, column, diagonal, and anti-diagonal. \r\n\r\nThe K-value is the Max minus the Minimum of the these products.\r\n\r\nExample: m=[5 1 8;3 9 4;7 2 6]\r\n\r\nRow Products: 40,108, and 84.  Column products 105, 18, and 192.\r\n\r\nDiagonal Products: 270, 1*4*7=28, and 8*3*2=48.\r\n\r\nAnti-Diagonal Products: 8*9*7=504, 1*3*6=18, and 5*4*2=40.\r\n\r\nK is thus 504-18 = 486.  [ Max of all products - Min of all products ]\r\n\r\n*Input:* Square Matrix\r\n\r\n*Output:* Kurchan Score\r\n\r\n*Related Challenges:*\r\n\r\n1) Minimize Kurchan Squares (N=4:9)\r\n\r\n2) Minimize Kurchan Squares (N=10:20) [Very large numbers]\r\n\r\n3) Maximize Sum of Products (N=4:9) and a Large number Challenge\r\n\r\n4) Minimize Sum of Products (N=4:9) and a Large number Challenge\r\n","description_html":"\u003cp\u003eEvaluate a Kurchan square. An NxN square with values 1:N^2.\u003c/p\u003e\u003cp\u003eGiven a square matrix determine the products of each row, column, diagonal, and anti-diagonal.\u003c/p\u003e\u003cp\u003eThe K-value is the Max minus the Minimum of the these products.\u003c/p\u003e\u003cp\u003eExample: m=[5 1 8;3 9 4;7 2 6]\u003c/p\u003e\u003cp\u003eRow Products: 40,108, and 84.  Column products 105, 18, and 192.\u003c/p\u003e\u003cp\u003eDiagonal Products: 270, 1*4*7=28, and 8*3*2=48.\u003c/p\u003e\u003cp\u003eAnti-Diagonal Products: 8*9*7=504, 1*3*6=18, and 5*4*2=40.\u003c/p\u003e\u003cp\u003eK is thus 504-18 = 486.  [ Max of all products - Min of all products ]\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Square Matrix\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Kurchan Score\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) Minimize Kurchan Squares (N=4:9)\u003c/p\u003e\u003cp\u003e2) Minimize Kurchan Squares (N=10:20) [Very large numbers]\u003c/p\u003e\u003cp\u003e3) Maximize Sum of Products (N=4:9) and a Large number Challenge\u003c/p\u003e\u003cp\u003e4) Minimize Sum of Products (N=4:9) and a Large number Challenge\u003c/p\u003e","function_template":"function K=kurchan_score(m)\r\n K=0;\r\nend","test_suite":"%%\r\nm=[5 1 8;3 9 4;7 2 6];\r\nK=kurchan_score(m) % 486\r\nassert(K==486)\r\n\r\n%%\r\nm=[1 24\t65 80 68 41 54 36 39\r\n49 51 28 14 67 57 77 2 45\r\n37 23 40 42 6 10 81 55 69\r\n74 58 3 30 16 43 32 44 70\r\n29 63 79 60 53 35 27 15 4\r\n52 8 31 62 72 73 5 50 25\r\n33 20 22 46 7 71 56 78 18\r\n61 21 38 9 48 13 19 76 66\r\n64 75 59 12 47 11 17 34 26];\r\ntic\r\nK=uint64(kurchan_score(m)) %  481200422400\r\ntoc\r\nassert(K==481200422400)\r\n%%\r\nv=[ 1     6     2     9     3     8     4     5     7]; % 366\r\nm=reshape(v,3,[]);\r\nK=uint64(kurchan_score(m))\r\nassert(K==366)\r\n%%\r\nv=[ 8    2    3    7    5    1    9    4    6]; % 486\r\nm=reshape(v,3,[]);\r\nK=uint64(kurchan_score(m))\r\nassert(K==486)\r\n%%\r\nv=[ 9 11 12 7 10 15 5 6 2 14 8 4 3 13 1 16];\r\nm=reshape(v,4,[]); % 29590\r\nK=uint64(kurchan_score(m))\r\nassert(K==29590)\r\n%%\r\nv=[ 1 16 15 6 12 3 2 8 7 9 14 13 10 11 4 5];\r\nm=reshape(v,4,[]); % 11256\r\nK=uint64(kurchan_score(m))\r\nassert(K==11256)\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-09T21:14:35.000Z","updated_at":"2025-12-05T13:26:41.000Z","published_at":"2013-06-09T21:43:14.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\u003eEvaluate a Kurchan square. An NxN square with values 1:N^2.\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\u003eGiven a square matrix determine the products of each row, column, diagonal, and anti-diagonal.\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 K-value is the Max minus the Minimum of the these products.\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\u003eExample: m=[5 1 8;3 9 4;7 2 6]\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\u003eRow Products: 40,108, and 84. Column products 105, 18, and 192.\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\u003eDiagonal Products: 270, 1*4*7=28, and 8*3*2=48.\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-Diagonal Products: 8*9*7=504, 1*3*6=18, and 5*4*2=40.\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\u003eK is thus 504-18 = 486. [ Max of all products - Min of all products ]\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 Square Matrix\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 Kurchan Score\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) Minimize Kurchan Squares (N=4:9)\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) Minimize Kurchan Squares (N=10:20) [Very large numbers]\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\u003e3) Maximize Sum of Products (N=4:9) and a Large number Challenge\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\u003e4) Minimize Sum of Products (N=4:9) and a Large number Challenge\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":1646,"title":"Kurchan 3x3 - Optimal Score","description":"Find an optimal 3x3 Kurchan square, score of 198. \r\n\r\nA 3x3 Kurchan square has values 1:9.The products of each row, column, diagonal, and anti-diagonal are used\r\n\r\nThe Kurchan-value is the Max minus the Minimum of these products.\r\n\r\n*Example: m=[5 1 8;3 9 4;7 2 6]*\r\n\r\nRow Products: 40,108, and 84. Column products 105, 18, and 192.\r\n\r\nDiagonal Products: 270, 1*4*7=28, and 8*3*2=48.\r\n\r\nAnti-Diagonal Products: 8*9*7=504, 1*3*6=18, and 5*4*2=40.\r\n\r\nK is thus 504-18 = 486. [ Max of all products - Min of all products ]\r\n\r\n*Input:* None\r\n\r\n*Output:* Kurchan Square [3x3] that scores 198\r\n\r\nI expect someone to give a min size hardcoded solution at some point.\r\n\r\nRelated Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function Kurchan Square Evaluation\u003e\r\n\r\n2) Minimize Kurchan Squares (N=4:9)\r\n\r\n3) Minimize Kurchan Squares (N=10:20) [Very large numbers]\r\n\r\n4) Maximize Sum of Products (N=4:9) and a Large number Challenge\r\n\r\n5) Minimize Sum of Products (N=4:9) and a Large number Challenge","description_html":"\u003cp\u003eFind an optimal 3x3 Kurchan square, score of 198.\u003c/p\u003e\u003cp\u003eA 3x3 Kurchan square has values 1:9.The products of each row, column, diagonal, and anti-diagonal are used\u003c/p\u003e\u003cp\u003eThe Kurchan-value is the Max minus the Minimum of these products.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample: m=[5 1 8;3 9 4;7 2 6]\u003c/b\u003e\u003c/p\u003e\u003cp\u003eRow Products: 40,108, and 84. Column products 105, 18, and 192.\u003c/p\u003e\u003cp\u003eDiagonal Products: 270, 1*4*7=28, and 8*3*2=48.\u003c/p\u003e\u003cp\u003eAnti-Diagonal Products: 8*9*7=504, 1*3*6=18, and 5*4*2=40.\u003c/p\u003e\u003cp\u003eK is thus 504-18 = 486. [ Max of all products - Min of all products ]\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e None\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Kurchan Square [3x3] that scores 198\u003c/p\u003e\u003cp\u003eI expect someone to give a min size hardcoded solution at some point.\u003c/p\u003e\u003cp\u003eRelated Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\"\u003eKurchan Square Evaluation\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Minimize Kurchan Squares (N=4:9)\u003c/p\u003e\u003cp\u003e3) Minimize Kurchan Squares (N=10:20) [Very large numbers]\u003c/p\u003e\u003cp\u003e4) Maximize Sum of Products (N=4:9) and a Large number Challenge\u003c/p\u003e\u003cp\u003e5) Minimize Sum of Products (N=4:9) and a Large number Challenge\u003c/p\u003e","function_template":"function m = kurchan_3x3\r\n  m=zeros(3);\r\nend","test_suite":"%%\r\ntic\r\nm = kurchan_3x3\r\ntoc\r\n p=[1     4     7\r\n     2     5     8\r\n     3     6     9\r\n     1     2     3\r\n     4     5     6\r\n     7     8     9\r\n     1     5     9\r\n     4     8     3\r\n     7     2     6\r\n     7     5     3\r\n     8     6     1\r\n     9     4     2];\r\nassert(isequal((1:9)',unique(m(:)))) % check use 1 thru 9\r\nmp=prod(m(p),2);\r\nK=max(mp)-min(mp) % display K score\r\n\r\n% simplified Kurchan scoring for 3x3\r\n\r\nassert(K\u003c=198)  % Pretty certain 198 is best possible, allow better score\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-13T04:20:37.000Z","updated_at":"2025-11-27T17:20:36.000Z","published_at":"2013-06-13T05:10:56.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\u003eFind an optimal 3x3 Kurchan square, score of 198.\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 3x3 Kurchan square has values 1:9.The products of each row, column, diagonal, and anti-diagonal are used\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 Kurchan-value is the Max minus the Minimum of these products.\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: m=[5 1 8;3 9 4;7 2 6]\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\u003eRow Products: 40,108, and 84. Column products 105, 18, and 192.\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\u003eDiagonal Products: 270, 1*4*7=28, and 8*3*2=48.\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-Diagonal Products: 8*9*7=504, 1*3*6=18, and 5*4*2=40.\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\u003eK is thus 504-18 = 486. [ Max of all products - Min of all products ]\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 None\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 Kurchan Square [3x3] that scores 198\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\u003eI expect someone to give a min size hardcoded solution at some point.\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\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/1634-kurchan-square-evaluation-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKurchan Square Evaluation\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) Minimize Kurchan Squares (N=4:9)\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\u003e3) Minimize Kurchan Squares (N=10:20) [Very large numbers]\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\u003e4) Maximize Sum of Products (N=4:9) and a Large number Challenge\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\u003e5) Minimize Sum of Products (N=4:9) and a Large number Challenge\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":2650,"title":"Kurchan 4x4 - Optimal score","description":"Related to Problem 1646, but bigger.  Technically, all you need to do for this Cody problem is input a 4x4 matrix containing the numbers 1-16.  However, your score will be the Kurchan value of the matrix, which is defined as the difference between the maximum and minimum of the products for the rows, columns, diagonals, and anti-diagonals of the matrix.\r\n\r\nFor example: Magic(4) is\r\n\r\n    16     2     3    13\r\n     5    11    10     8\r\n     9     7     6    12\r\n     4    14    15     1\r\n\r\nThe row products are:\r\n\r\n* 16*2*3*13=1248\r\n* 5*11*10*8=4400\r\n* 9*7*6*12=4536\r\n* 4*14*15*1=840\r\n\r\nThe column products are:\r\n\r\n* 16*9*5*4=2880\r\n* 2*11*7*14=2156\r\n* 3*10*6*15=2700\r\n* 13*8*12*1=1248\r\n\r\nThe diagonal products are:\r\n\r\n* 16*11*6*1=1056\r\n* 2*10*12*4=960\r\n* 3*8*9*14=3024\r\n* 13*5*7*15=6825\r\n\r\nThe anti-diagonal products are:\r\n\r\n* 13*10*7*4=3640\r\n* 3*11*9*1=297\r\n* 2*5*12*15=1800\r\n* 16*8*6*14=10752\r\n\r\nThe highest value is 10752, while the lowest is 297.  Therefore, the score of this matrix is 10455.  Your Cody score will be the Kurchan score of your matrix.","description_html":"\u003cp\u003eRelated to Problem 1646, but bigger.  Technically, all you need to do for this Cody problem is input a 4x4 matrix containing the numbers 1-16.  However, your score will be the Kurchan value of the matrix, which is defined as the difference between the maximum and minimum of the products for the rows, columns, diagonals, and anti-diagonals of the matrix.\u003c/p\u003e\u003cp\u003eFor example: Magic(4) is\u003c/p\u003e\u003cpre\u003e    16     2     3    13\r\n     5    11    10     8\r\n     9     7     6    12\r\n     4    14    15     1\u003c/pre\u003e\u003cp\u003eThe row products are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e16*2*3*13=1248\u003c/li\u003e\u003cli\u003e5*11*10*8=4400\u003c/li\u003e\u003cli\u003e9*7*6*12=4536\u003c/li\u003e\u003cli\u003e4*14*15*1=840\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe column products are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e16*9*5*4=2880\u003c/li\u003e\u003cli\u003e2*11*7*14=2156\u003c/li\u003e\u003cli\u003e3*10*6*15=2700\u003c/li\u003e\u003cli\u003e13*8*12*1=1248\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe diagonal products are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e16*11*6*1=1056\u003c/li\u003e\u003cli\u003e2*10*12*4=960\u003c/li\u003e\u003cli\u003e3*8*9*14=3024\u003c/li\u003e\u003cli\u003e13*5*7*15=6825\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe anti-diagonal products are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e13*10*7*4=3640\u003c/li\u003e\u003cli\u003e3*11*9*1=297\u003c/li\u003e\u003cli\u003e2*5*12*15=1800\u003c/li\u003e\u003cli\u003e16*8*6*14=10752\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe highest value is 10752, while the lowest is 297.  Therefore, the score of this matrix is 10455.  Your Cody score will be the Kurchan score of your matrix.\u003c/p\u003e","function_template":"function y = kurchan_4x4\r\n% Input your code to generate the matrix here, or hardcode it.\r\n  y = x;\r\nend","test_suite":"%%\r\ny = kurchan_4x4\r\nuy=unique(y(:));\r\nassert(isequal(uy,[1:16]'));\r\n\r\ndg = @(mm) spdiags([mm mm],1:length(mm));\r\npy=prod([y y' dg(y) dg(flipud(y))]);\r\ncody_score=max(py)-min(py);\r\n\r\nfprintf('Maximum product of your matrix = %.0f \\n',max(py))\r\nfprintf('Minimum product of your matrix = %.0f \\n',min(py))\r\nfprintf('Kurchan score of your matrix   = %.0f \\n',cody_score)\r\nfeval(@assignin,'caller','score',cody_score);","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-10-30T18:17:14.000Z","updated_at":"2026-03-11T13:32:02.000Z","published_at":"2014-10-30T18:17:13.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\u003eRelated to Problem 1646, but bigger. Technically, all you need to do for this Cody problem is input a 4x4 matrix containing the numbers 1-16. However, your score will be the Kurchan value of the matrix, which is defined as the difference between the maximum and minimum of the products for the rows, columns, diagonals, and anti-diagonals of the matrix.\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\u003eFor example: Magic(4) is\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[    16     2     3    13\\n     5    11    10     8\\n     9     7     6    12\\n     4    14    15     1]]\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:t\u003eThe row products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16*2*3*13=1248\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5*11*10*8=4400\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e9*7*6*12=4536\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4*14*15*1=840\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 column products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16*9*5*4=2880\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2*11*7*14=2156\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3*10*6*15=2700\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e13*8*12*1=1248\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 diagonal products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16*11*6*1=1056\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2*10*12*4=960\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3*8*9*14=3024\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e13*5*7*15=6825\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 anti-diagonal products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e13*10*7*4=3640\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3*11*9*1=297\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2*5*12*15=1800\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16*8*6*14=10752\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 highest value is 10752, while the lowest is 297. Therefore, the score of this matrix is 10455. Your Cody score will be the Kurchan score of your matrix.\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":2652,"title":"Kurchan 5x5 - Optimal Score","description":"Related to Problems 1646 and 2650, but bigger. Technically, all you need to do for this Cody problem is input a 5x5 matrix containing the numbers 1-25. However, your score will be the Kurchan value of the matrix, which is defined as the difference between the maximum and minimum of the products for the rows, columns, diagonals, and anti-diagonals of the matrix.\r\nFor example: Magic(5) is\r\n    17    24     1     8    15\r\n    23     5     7    14    16\r\n     4     6    13    20    22\r\n    10    12    19    21     3\r\n    11    18    25     2     9\r\nThe row products are:\r\n17 * 24 * 1 * 8 * 15=48960\r\n23 * 5 * 7 * 14 * 16=180320\r\n4 * 6 * 13 * 20 * 22=137280\r\n10 * 12 * 19 * 21 * 3=143640\r\n11 * 18 * 25 * 2 * 9=89100\r\nThe column products are:\r\n17 * 23 * 4 * 10 * 11=172040\r\n24 * 5 * 6 * 12 * 18=155520\r\n1 * 7 * 13 * 19 * 25=43225\r\n8 * 14 * 20 * 21 * 2=94080\r\n15 * 16 * 22 * 3 * 9=142560\r\nThe diagonal products are:\r\n17*5*13*21*9=208845\r\n24*7*20*3*11=110880\r\n1*14*22*10*18=55440\r\n8*16*4*12*25=153600\r\n15*23*6*19*2=78660\r\nThe anti-diagonal products are:\r\n15*14*13*12*11=360360\r\n8*7*6*10*9=30240\r\n1*5*4*3*2=120\r\n24*23*22*21*25=6375600\r\n17*16*20*19*18=1860480\r\nThe highest value is 6375600, while the lowest is 120. Therefore, the score of this matrix is 6375480. Your Cody score will be the Kurchan score of your matrix.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 890.833px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 445.417px; transform-origin: 407px 445.417px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 42px; text-align: left; transform-origin: 384px 42px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 8px; transform-origin: 383.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRelated to Problems 1646 and 2650, but bigger. Technically, all you need to do for this Cody problem is input a 5x5 matrix containing the numbers 1-25. However, your score will be the Kurchan value of the matrix, which is defined as the difference between the maximum and minimum of the products for the rows, columns, diagonals, and anti-diagonals of the matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 77.5px 8px; transform-origin: 77.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example: Magic(5) is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 102.167px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 51.0833px; transform-origin: 404px 51.0833px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    17    24     1     8    15\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    23     5     7    14    16\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     4     6    13    20    22\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    10    12    19    21     3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    11    18    25     2     9\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 69.5px 8px; transform-origin: 69.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe row products are:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 102.167px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 51.0833px; transform-origin: 391px 51.0833px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 82px 8px; transform-origin: 82px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e17 * 24 * 1 * 8 * 15=48960\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 86px 8px; transform-origin: 86px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e23 * 5 * 7 * 14 * 16=180320\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 86px 8px; transform-origin: 86px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e4 * 6 * 13 * 20 * 22=137280\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 90px 8px; transform-origin: 90px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e10 * 12 * 19 * 21 * 3=143640\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 81.5px 8px; transform-origin: 81.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e11 * 18 * 25 * 2 * 9=89100\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 81px 8px; transform-origin: 81px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe column products are:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 102.167px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 51.0833px; transform-origin: 391px 51.0833px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 89.5px 8px; transform-origin: 89.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e17 * 23 * 4 * 10 * 11=172040\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 86px 8px; transform-origin: 86px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e24 * 5 * 6 * 12 * 18=155520\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 82px 8px; transform-origin: 82px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1 * 7 * 13 * 19 * 25=43225\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 82px 8px; transform-origin: 82px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e8 * 14 * 20 * 21 * 2=94080\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 86px 8px; transform-origin: 86px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e15 * 16 * 22 * 3 * 9=142560\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 85.5px 8px; transform-origin: 85.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe diagonal products are:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 102.167px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 51.0833px; transform-origin: 391px 51.0833px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e17*5*13*21*9=208845\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 69px 8px; transform-origin: 69px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e24*7*20*3*11=110880\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1*14*22*10*18=55440\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e8*16*4*12*25=153600\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 66px 8px; transform-origin: 66px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e15*23*6*19*2=78660\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 99.5px 8px; transform-origin: 99.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe anti-diagonal products are:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 102.167px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 51.0833px; transform-origin: 391px 51.0833px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 77.5px 8px; transform-origin: 77.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e15*14*13*12*11=360360\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 58px 8px; transform-origin: 58px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e8*7*6*10*9=30240\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 46px 8px; transform-origin: 46px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1*5*4*3*2=120\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 82px 8px; transform-origin: 82px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e24*23*22*21*25=6375600\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 82px 8px; transform-origin: 82px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e17*16*20*19*18=1860480\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe highest value is 6375600, while the lowest is 120. Therefore, the score of this matrix is 6375480. Your Cody score will be the Kurchan score of your matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = kurchan_5x5\r\n  % Input your matrix or code below\r\ny=magic(5)\r\nend","test_suite":"%%\r\ny = kurchan_5x5\r\nuy=unique(y(:));\r\nassert(isequal(uy,[1:25]'));\r\n\r\ndg = @(mm) spdiags([mm mm],1:length(mm));\r\npy=prod([y y' dg(y) dg(flipud(y))]);\r\ncody_score=max(py)-min(py);\r\n\r\nfprintf('Maximum product of your matrix = %.0f \\n',max(py))\r\nfprintf('Minimum product of your matrix = %.0f \\n',min(py))\r\nfprintf('Kurchan score of your matrix   = %.0f \\n',cody_score)\r\nfeval(@assignin,'caller','score',cody_score);","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2021-10-02T19:34:56.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-10-31T14:35:09.000Z","updated_at":"2026-03-16T13:30:43.000Z","published_at":"2014-10-31T14:39:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated to Problems 1646 and 2650, but bigger. Technically, all you need to do for this Cody problem is input a 5x5 matrix containing the numbers 1-25. However, your score will be the Kurchan value of the matrix, which is defined as the difference between the maximum and minimum of the products for the rows, columns, diagonals, and anti-diagonals of the matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example: Magic(5) is\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[    17    24     1     8    15\\n    23     5     7    14    16\\n     4     6    13    20    22\\n    10    12    19    21     3\\n    11    18    25     2     9]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe row products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e17 * 24 * 1 * 8 * 15=48960\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e23 * 5 * 7 * 14 * 16=180320\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4 * 6 * 13 * 20 * 22=137280\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e10 * 12 * 19 * 21 * 3=143640\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e11 * 18 * 25 * 2 * 9=89100\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe column products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e17 * 23 * 4 * 10 * 11=172040\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e24 * 5 * 6 * 12 * 18=155520\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 * 7 * 13 * 19 * 25=43225\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e8 * 14 * 20 * 21 * 2=94080\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e15 * 16 * 22 * 3 * 9=142560\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe diagonal products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e17*5*13*21*9=208845\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e24*7*20*3*11=110880\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1*14*22*10*18=55440\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e8*16*4*12*25=153600\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e15*23*6*19*2=78660\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe anti-diagonal products are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e15*14*13*12*11=360360\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e8*7*6*10*9=30240\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1*5*4*3*2=120\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e24*23*22*21*25=6375600\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e17*16*20*19*18=1860480\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe highest value is 6375600, while the lowest is 120. Therefore, the score of this matrix is 6375480. Your Cody score will be the Kurchan score of your matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1854,"title":"Factorial: Unlimited Size : java.math","description":"This challenge is an application of java.math that allows unlimited precision calculations.  The primary reference sites are \u003chttp://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Number.html Java Math\u003e, \u003chttp://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html Java BigDecimal\u003e, and \u003chttp://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigInteger.html Java BigInteger\u003e.\r\n\r\nThe usage of BigDecimal function multiply will be essential.\r\n\r\nJava Math tutorial: (Simplified summary that is believed correct)\r\n\r\n  vd-decimal value, vstr-string, vi-integer value \r\n  xBD=java.math.BigDecimal(vd);  % valid vd,vstr,vi creates xBD a BigDecimal variable\r\n  import java.math.*;  % simplifies statements\r\n  xBD=BigDecimal(vstr);\r\n \r\n  xmultiplyzBD=xBD.multiply(BigDecimal(z));  % multiply input requires BD type\r\n  \r\n  To convert java to string of unlimited length can be achieved via java toString or Matlab char\r\n  \r\n  xstr=toString(xBD)  or xstr=char(xBD) \r\n\r\n*Input:* N  [1\u003c N \u003c 1000]\r\n\r\n*Output:* Y  (char variable of Y=N! or a BigDecimal variable)\r\n\r\n\u003chttp://www.nitrxgen.net/factorialcalc.php Factorial Calculator\u003e\r\n\r\n*Related Challenges:*\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/1833-usage-of-java-math-add-multiply-pow 1. Usage of java math\u003e\r\n\r\n  2. nchoosek_large (full precision)\r\n  2. Next Prime\r\n  3. factor_large\r\n  4. Factorial","description_html":"\u003cp\u003eThis challenge is an application of java.math that allows unlimited precision calculations.  The primary reference sites are \u003ca href = \"http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Number.html\"\u003eJava Math\u003c/a\u003e, \u003ca href = \"http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html\"\u003eJava BigDecimal\u003c/a\u003e, and \u003ca href = \"http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigInteger.html\"\u003eJava BigInteger\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eThe usage of BigDecimal function multiply will be essential.\u003c/p\u003e\u003cp\u003eJava Math tutorial: (Simplified summary that is believed correct)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003evd-decimal value, vstr-string, vi-integer value \r\nxBD=java.math.BigDecimal(vd);  % valid vd,vstr,vi creates xBD a BigDecimal variable\r\nimport java.math.*;  % simplifies statements\r\nxBD=BigDecimal(vstr);\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003exmultiplyzBD=xBD.multiply(BigDecimal(z));  % multiply input requires BD type\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eTo convert java to string of unlimited length can be achieved via java toString or Matlab char\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003exstr=toString(xBD)  or xstr=char(xBD) \r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e N  [1\u0026lt; N \u0026lt; 1000]\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Y  (char variable of Y=N! or a BigDecimal variable)\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.nitrxgen.net/factorialcalc.php\"\u003eFactorial Calculator\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1833-usage-of-java-math-add-multiply-pow\"\u003e1. Usage of java math\u003c/a\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e2. nchoosek_large (full precision)\r\n2. Next Prime\r\n3. factor_large\r\n4. Factorial\r\n\u003c/pre\u003e","function_template":"function y = factorialJava(N)\r\n import java.math.*\r\n y = num2str(factorial(N));\r\nend","test_suite":"%%\r\ntic\r\nN=69;\r\ny = factorialJava(N);\r\nassert(strcmp(y,'171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000'))\r\ntoc\r\n%%\r\ntic\r\nN=randi(18)\r\ny = factorialJava(N);\r\nassert(strcmp(y,num2str(factorial(N))))\r\ntoc\r\n%%\r\ntic\r\nN=randi(18)\r\ny = factorialJava(N);\r\nassert(strcmp(y,num2str(factorial(N))))\r\ntoc\r\n%%\r\ntic\r\nN=1000;\r\ny = factorialJava(N);\r\nassert(strcmp(y,'402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'))\r\ntoc\r\n%%\r\ntic\r\nN=42;\r\ny = factorialJava(N);\r\nassert(strcmp(y,'1405006117752879898543142606244511569936384000000000'))\r\ntoc\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":47,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-30T01:59:14.000Z","updated_at":"2025-12-10T03:30:57.000Z","published_at":"2013-08-30T02:37:28.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 challenge is an application of java.math that allows unlimited precision calculations. The primary reference sites are\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://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Number.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eJava Math\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\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://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eJava BigDecimal\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and\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://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigInteger.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eJava BigInteger\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\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:t\u003eThe usage of BigDecimal function multiply will be essential.\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\u003eJava Math tutorial: (Simplified summary that is believed correct)\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[vd-decimal value, vstr-string, vi-integer value \\nxBD=java.math.BigDecimal(vd);  % valid vd,vstr,vi creates xBD a BigDecimal variable\\nimport java.math.*;  % simplifies statements\\nxBD=BigDecimal(vstr);\\n\\nxmultiplyzBD=xBD.multiply(BigDecimal(z));  % multiply input requires BD type\\n\\nTo convert java to string of unlimited length can be achieved via java toString or Matlab char\\n\\nxstr=toString(xBD)  or xstr=char(xBD)]]\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 N [1\u0026lt; N \u0026lt; 1000]\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 Y (char variable of Y=N! or a BigDecimal variable)\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:hyperlink w:docLocation=\\\"http://www.nitrxgen.net/factorialcalc.php\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFactorial Calculator\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: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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1833-usage-of-java-math-add-multiply-pow\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1. Usage of java math\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[2. nchoosek_large (full precision)\\n2. Next Prime\\n3. factor_large\\n4. Factorial]]\u003e\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":1941,"title":"Lowest sum from a group of digits","description":"Hi there.  It's James's daughter here again, and my third grade math teacher is up to her old tricks.  This time, she's giving us an even number of digits between 0-9, and she wants us to come up with the smallest possible sum of two numbers that are the same length.\r\n\r\nFor example, if we're given [0 1 2 3], the smallest sum we can get using those numbers by adding two 2-digit numbers together is 33.  That's either 10+23 or 13+20.  We don't need to know what the two original numbers are, just what their sum is.  We also can't start any of our numbers with a zero, because that's cheating.\r\n\r\nYou guys did a great job with my earlier problems, and even taught my dad a few things about MATLAB!  I hope you can help me out with this one as well!","description_html":"\u003cp\u003eHi there.  It's James's daughter here again, and my third grade math teacher is up to her old tricks.  This time, she's giving us an even number of digits between 0-9, and she wants us to come up with the smallest possible sum of two numbers that are the same length.\u003c/p\u003e\u003cp\u003eFor example, if we're given [0 1 2 3], the smallest sum we can get using those numbers by adding two 2-digit numbers together is 33.  That's either 10+23 or 13+20.  We don't need to know what the two original numbers are, just what their sum is.  We also can't start any of our numbers with a zero, because that's cheating.\u003c/p\u003e\u003cp\u003eYou guys did a great job with my earlier problems, and even taught my dad a few things about MATLAB!  I hope you can help me out with this one as well!\u003c/p\u003e","function_template":"function y = lowest_number(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0:3; y_correct = 33; assert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx=[1 2 3 7 8 9] ; y_correct = 417; \r\nassert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx=[7 8 9 7 8 9] ; y_correct = 1578; \r\nassert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx = 0:9; y_correct = 34047; assert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx=7*[ones(1,5) zeros(1,7)]; y_correct=1400084; assert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx=[ones(1,8) zeros(1,10)]; y_correct=200000222; assert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx = [0:9 1:8]; y_correct = 225802467; assert(isequal(lowest_number(x),y_correct))\r\n%%\r\nx=[randperm(10)-1 randperm(6)]; y_correct=22580247; assert(isequal(lowest_number(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":3,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":55,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-10-17T16:55:16.000Z","updated_at":"2025-12-07T10:12:33.000Z","published_at":"2013-10-17T16:55:16.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eHi there. It's James's daughter here again, and my third grade math teacher is up to her old tricks. This time, she's giving us an even number of digits between 0-9, and she wants us to come up with the smallest possible sum of two numbers that are the same length.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if we're given [0 1 2 3], the smallest sum we can get using those numbers by adding two 2-digit numbers together is 33. That's either 10+23 or 13+20. We don't need to know what the two original numbers are, just what their sum is. We also can't start any of our numbers with a zero, because that's cheating.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou guys did a great job with my earlier problems, and even taught my dad a few things about MATLAB! I hope you can help me out with this one as well!\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":2488,"title":"Create all combinations of vectors","description":"This function exists in the Neural Network Toolbox but is not available in Cody. Can you write such a function? \r\n\r\nSee \u003chttp://www.mathworks.com/help/nnet/ref/combvec.html combvec\u003e for more information.\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThis function exists in the Neural Network Toolbox but is not available in Cody. Can you write such a function?\u003c/p\u003e\u003cp\u003eSee \u003ca href = \"http://www.mathworks.com/help/nnet/ref/combvec.html\"\u003ecombvec\u003c/a\u003e for more information.\u003c/p\u003e","function_template":"function D = combina(varargin)\r\n\r\n\r\nend\r\n","test_suite":"%%\r\na1=[1 2 3; 4 5 6];\r\na2 = [7 8; 9 10];\r\n\r\nD =[\r\n\r\n     1     2     3     1     2     3\r\n     4     5     6     4     5     6\r\n     7     7     7     8     8     8\r\n     9     9     9    10    10    10];\r\nassert(isequal(combina(a1,a2),D));\r\n%%\r\na1=[1 2 3; 4 5 6];\r\na2 = [7 8; 9 10];\r\na3=[2 3 4;4 5 6];\r\n\r\nD =[\r\n\r\n     1     2     3     1     2     3     1     2     3     1     2     3     1     2     3     1     2     3\r\n     4     5     6     4     5     6     4     5     6     4     5     6     4     5     6     4     5     6\r\n     7     7     7     8     8     8     7     7     7     8     8     8     7     7     7     8     8     8\r\n     9     9     9    10    10    10     9     9     9    10    10    10     9     9     9    10    10    10\r\n     2     2     2     2     2     2     3     3     3     3     3     3     4     4     4     4     4     4\r\n     4     4     4     4     4     4     5     5     5     5     5     5     6     6     6     6     6     6];\r\nassert(isequal(combina(a1,a2,a3),D));\r\n%%\r\na1=[1 2 ];\r\na2 = [7 8];\r\na3=[2 3 ];\r\na4=[1 1];\r\nD=[1     2     1     2     1     2     1     2     1     2     1     2     1     2     1     2\r\n     7     7     8     8     7     7     8     8     7     7     8     8     7     7     8     8\r\n     2     2     2     2     3     3     3     3     2     2     2     2     3     3     3     3\r\n     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1]\r\n\r\nassert(isequal(combina(a1,a2,a3,a4),D));\r\n%%\r\na1=[1 2 ];\r\na2 = [7 ];\r\na3=[2  ];\r\na4=[1 ]\r\nD=[1     2\r\n     7     7\r\n     2     2\r\n     1     1];\r\n\r\nassert(isequal(combina(a1,a2,a3,a4),D));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":"2014-08-07T08:07:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-07T07:56:06.000Z","updated_at":"2025-12-05T13:22:35.000Z","published_at":"2014-08-07T08:07:07.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 function exists in the Neural Network Toolbox but is not available in Cody. Can you write such a function?\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\u003eSee\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/help/nnet/ref/combvec.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecombvec\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for more information.\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":42790,"title":"Full combinations","description":"Given n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \"increasing\" ordering; see examples below.  \r\n\r\n* Example 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output: \r\n\r\n\r\n    y = ['ac'\r\n         'ad'\r\n         'ae'\r\n         'bc'\r\n         'bd'\r\n         'be'] \r\n\r\n\r\n* Example 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output: \r\n\r\n    y = [0 0 0\r\n         0 0 1\r\n         0 1 0\r\n         0 1 1\r\n         1 0 0\r\n         1 0 1\r\n         1 1 0\r\n         1 1 1]\r\n\r\n\r\nYou may assume that all inputs are valid vectors whose lengths are at least 1. \r\n \r\n\r\nNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely *ff2n* (for binary case) and *fullfact* (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\r\n","description_html":"\u003cp\u003eGiven n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \"increasing\" ordering; see examples below.\u003c/p\u003e\u003cul\u003e\u003cli\u003eExample 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:\u003c/li\u003e\u003c/ul\u003e\u003cpre\u003e    y = ['ac'\r\n         'ad'\r\n         'ae'\r\n         'bc'\r\n         'bd'\r\n         'be'] \u003c/pre\u003e\u003cul\u003e\u003cli\u003eExample 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:\u003c/li\u003e\u003c/ul\u003e\u003cpre\u003e    y = [0 0 0\r\n         0 0 1\r\n         0 1 0\r\n         0 1 1\r\n         1 0 0\r\n         1 0 1\r\n         1 1 0\r\n         1 1 1]\u003c/pre\u003e\u003cp\u003eYou may assume that all inputs are valid vectors whose lengths are at least 1.\u003c/p\u003e\u003cp\u003eNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely \u003cb\u003eff2n\u003c/b\u003e (for binary case) and \u003cb\u003efullfact\u003c/b\u003e (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\u003c/p\u003e","function_template":"function y = myfullfact(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx1 = [0 1]; x2 = [0 1]; x3 = [0 1];\r\ny_correct = [0 0 0\r\n             0 0 1\r\n             0 1 0\r\n             0 1 1\r\n             1 0 0\r\n             1 0 1\r\n             1 1 0\r\n             1 1 1];\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%%\r\nx1 = [0 1]; x2 = [-1]; x3 = [-1 0 1];\r\ny_correct = [0  -1  -1\r\n             0  -1   0\r\n             0  -1   1\r\n             1  -1  -1\r\n             1  -1   0\r\n             1  -1   1];\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%% \r\nx1 = 0; x2 = 2; x3 = 4; x4 = 8; x5 = 7; x6 = 6; x7 = 4; x8 = 1; x9 = 1; x10 = 0;\r\ny_correct = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10];\r\nassert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10),y_correct))\r\n\r\n%%\r\nx1 = 'ab'; x2 = 'cde';\r\ny_correct = ['ac'\r\n             'ad'\r\n             'ae'\r\n             'bc'\r\n             'bd'\r\n             'be'];\r\nassert(isequal(myfullfact(x1,x2),y_correct))\r\n\r\n%%\r\nx1 = 'a'; x2 = 'a'; x3 = 'z';\r\ny_correct = 'aaz';\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%%\r\nx1 = '!@#'; x2 = '23';\r\ny_correct = ['!2'\r\n             '!3'\r\n             '@2'\r\n             '@3'\r\n             '#2'\r\n             '#3'];\r\nassert(isequal(myfullfact(x1,x2),y_correct))\r\n\r\n%%\r\nx1 = '@#'; x2 = 'm'; x3 = 'a'; x4 = 't'; x5 = 'l'; x6 = 'a'; x7 = 'b'; x8 = '$%*';\r\ny_correct = ['@matlab$'\r\n             '@matlab%'\r\n             '@matlab*'\r\n             '#matlab$'\r\n             '#matlab%'\r\n             '#matlab*'];\r\nassert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8),y_correct))\r\n\r\n%%\r\n% A manual implementation used to validate other solutions. Please be advised that generalization of this is straightforward but inefficient in terms of Cody size. To get a solution with possibly smaller size, try different ideas please.  \r\nfor iter = 1:20\r\n    a = randi(10,5,1);\r\n    x = arrayfun(@(x)(1:x).',a,'un',0);\r\n    [x1,x2,x3,x4,x5] = deal(x{:});\r\n    y1 = repelem(x1, prod(a(2:5)), 1);\r\n    y2 = repmat(repelem(x2, prod(a(3:5)), 1), a(1), 1);\r\n    y3 = repmat(repelem(x3, prod(a(4:5)), 1), prod(a(1:2)), 1);\r\n    y4 = repmat(repelem(x4, a(5), 1), prod(a(1:3)), 1);\r\n    y5 = repmat(x5, prod(a(1:4)), 1); \r\n    y_correct = [y1, y2, y3, y4, y5];\r\n    assert(isequal(myfullfact(x1,x2,x3,x4,x5),y_correct));\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":"2016-03-29T21:03:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-29T19:44:39.000Z","updated_at":"2025-12-05T13:12:00.000Z","published_at":"2016-03-29T19:47:42.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\u003eGiven n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \\\"increasing\\\" ordering; see examples below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:\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[    y = ['ac'\\n         'ad'\\n         'ae'\\n         'bc'\\n         'bd'\\n         'be']]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:\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[    y = [0 0 0\\n         0 0 1\\n         0 1 0\\n         0 1 1\\n         1 0 0\\n         1 0 1\\n         1 1 0\\n         1 1 1]]]\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:t\u003eYou may assume that all inputs are valid vectors whose lengths are at least 1.\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\u003eNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eff2n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (for binary case) and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efullfact\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\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":160,"title":"So many choices","description":"For inputs _n_ and _k_ (in that order), output the number of ways that k objects can be chosen from amongst n distinct objects. [The order of the selected objects is irrelevant.]\r\n\r\nFor example, suppose you have 4 blocks: red, green, blue, yellow. How many ways are there to select 2 of them? There are 6 ways: RG, RB, RY, GB, GY, BY. [Remember the ordering is irrelevant, so GR is equivalent to RG, and therefore does not count as a distinct choice.]\r\n\r\nSo, function(4,2) ---\u003e 6.","description_html":"\u003cp\u003eFor inputs \u003ci\u003en\u003c/i\u003e and \u003ci\u003ek\u003c/i\u003e (in that order), output the number of ways that k objects can be chosen from amongst n distinct objects. [The order of the selected objects is irrelevant.]\u003c/p\u003e\u003cp\u003eFor example, suppose you have 4 blocks: red, green, blue, yellow. How many ways are there to select 2 of them? There are 6 ways: RG, RB, RY, GB, GY, BY. [Remember the ordering is irrelevant, so GR is equivalent to RG, and therefore does not count as a distinct choice.]\u003c/p\u003e\u003cp\u003eSo, function(4,2) ---\u003e 6.\u003c/p\u003e","function_template":"function y = fcn(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nn = 1;\r\nk = 1;\r\ny_correct = 1;\r\nassert(isequal(fcn(n,k),y_correct))\r\n%%\r\nn = 4;\r\nk = 2;\r\ny_correct = 6;\r\nassert(isequal(fcn(n,k),y_correct))\r\n%%\r\nn = 20;\r\nk = 10;\r\ny_correct = 184756;\r\nassert(isequal(fcn(n,k),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":39,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":473,"test_suite_updated_at":"2012-01-29T05:15:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-29T05:15:18.000Z","updated_at":"2026-03-06T14:00:09.000Z","published_at":"2012-02-02T14:11:44.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\u003eFor inputs\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ek\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (in that order), output the number of ways that k objects can be chosen from amongst n distinct objects. [The order of the selected objects is irrelevant.]\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\u003eFor example, suppose you have 4 blocks: red, green, blue, yellow. How many ways are there to select 2 of them? There are 6 ways: RG, RB, RY, GB, GY, BY. [Remember the ordering is irrelevant, so GR is equivalent to RG, and therefore does not count as a distinct choice.]\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\u003eSo, function(4,2) ---\u0026gt; 6.\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":42615,"title":"Factorizing a number into a given number of factors","description":"Given a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\r\n\r\nNote: The number 1 is also considered a valid factor.\r\n\r\nExample 1:\r\n\r\nn = 30\r\n\r\nb = 2\r\n\r\nM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\r\n\r\nExample 2:\r\n\r\nn = 120\r\n\r\nb = 3\r\n\r\nM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]","description_html":"\u003cp\u003eGiven a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\u003c/p\u003e\u003cp\u003eNote: The number 1 is also considered a valid factor.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cp\u003en = 30\u003c/p\u003e\u003cp\u003eb = 2\u003c/p\u003e\u003cp\u003eM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\u003c/p\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cp\u003en = 120\u003c/p\u003e\u003cp\u003eb = 3\u003c/p\u003e\u003cp\u003eM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]\u003c/p\u003e","function_template":"function M = LtdFactor(n,b)\r\n  M = [ n b ];\r\nend","test_suite":"%%\r\nn = 30;\r\nb = 1;\r\nA_correct = [ 30 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 3135;\r\nb = 2;\r\nA_correct = [ 1 3135 ; 3 1045 ; 5 627 ; 11 285 ; 15 209 ; 19 165 ; 33 95 ; 55 57 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 120;\r\nb = 3;\r\nA_correct = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 420;\r\nb = 4;\r\nA_correct = [ 1 1 1 420 ; 1 1 2 210 ; 1 1 3 140 ; 1 1 4 105 ; 1 1 5 84 ; 1 1 6 70 ; 1 1 7 60 ; 1 1 10 42 ; 1 1 12 35 ; 1 1 14 30 ; 1 1 15 28 ; 1 1 20 21 ; 1 2 2 105 ; 1 2 3 70 ; 1 2 5 42 ; 1 2 6 35 ; 1 2 7 30 ; 1 2 10 21 ; 1 2 14 15 ; 1 3 4 35 ; 1 3 5 28 ; 1 3 7 20 ; 1 3 10 14 ; 1 4 5 21 ; 1 4 7 15 ; 1 5 6 14 ; 1 5 7 12 ; 1 6 7 10 ; 2 2 3 35 ; 2 2 5 21 ; 2 2 7 15 ; 2 3 5 14 ; 2 3 7 10 ; 2 5 6 7 ; 3 4 5 7 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 2025;\r\nb = 3;\r\nA_correct = [ 1 1 2025 ; 1 3 675 ; 1 5 405 ; 1 9 225 ; 1 15 135 ; 1 25 81 ; 1 27 75 ; 1 45 45 ; 3 3 225 ; 3 5 135 ; 3 9 75 ; 3 15 45 ; 3 25 27 ; 5 5 81 ; 5 9 45 ; 5 15 27 ; 9 9 25 ; 9 15 15 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 210;\r\nb = 4;\r\nA_correct = [ 1 1 1 210 ; 1 1 2 105 ; 1 1 3 70 ; 1 1 5 42 ; 1 1 6 35 ; 1 1 7 30 ; 1 1 10 21 ; 1 1 14 15 ; 1 2 3 35 ; 1 2 5 21 ; 1 2 7 15 ; 1 3 5 14 ; 1 3 7 10 ; 1 5 6 7 ; 2 3 5 7 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-09-14T09:47:56.000Z","updated_at":"2025-12-05T13:06:40.000Z","published_at":"2015-09-14T10:33:10.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eGiven a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: The number 1 is also considered a valid factor.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 30\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb = 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 120\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb = 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]\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":42918,"title":"Addition Partition","description":"You will be given two numbers, N and K.  Write a MATLAB function that will determine how many different unique ways you can have K numbers add up to N.  The numbers you use can be anything from 0-N, but no negatives and no fractions.  For example, five can be the sum of three numbers in five different ways:\r\n\r\n* 5+0+0\r\n* 4+1+0\r\n* 3+2+0\r\n* 3+1+1\r\n* 2+2+1\r\n\r\nOrder does not matter, so (5,0,0) is the same as (0,0,5) and (0,5,0).  Therefore, the output of your function num_sum(5,3) should be 5.  I don't need the different permutations, only how many there are.  Good luck!","description_html":"\u003cp\u003eYou will be given two numbers, N and K.  Write a MATLAB function that will determine how many different unique ways you can have K numbers add up to N.  The numbers you use can be anything from 0-N, but no negatives and no fractions.  For example, five can be the sum of three numbers in five different ways:\u003c/p\u003e\u003cul\u003e\u003cli\u003e5+0+0\u003c/li\u003e\u003cli\u003e4+1+0\u003c/li\u003e\u003cli\u003e3+2+0\u003c/li\u003e\u003cli\u003e3+1+1\u003c/li\u003e\u003cli\u003e2+2+1\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eOrder does not matter, so (5,0,0) is the same as (0,0,5) and (0,5,0).  Therefore, the output of your function num_sum(5,3) should be 5.  I don't need the different permutations, only how many there are.  Good luck!\u003c/p\u003e","function_template":"function y = num_sum(N,K)\r\n  y = N*K;\r\nend","test_suite":"%%\r\nN=5;K=3;\r\nassert(isequal(num_sum(N,K),5))\r\n%%\r\nN=7;K=4;\r\nassert(isequal(num_sum(N,K),11))\r\n%%\r\nN=7;K=3;\r\nassert(isequal(num_sum(N,K),8))\r\n%%\r\nN=15;K=6;\r\nassert(isequal(num_sum(N,K),110))\r\n%%\r\nN=20;K=4;\r\nassert(isequal(num_sum(N,K),108))\r\n%%\r\nN=12;K=9;\r\nassert(isequal(num_sum(N,K),73))\r\n%%\r\nN=13;K=3;\r\nassert(isequal(num_sum(N,K),21))\r\n%%\r\nN=12;K=2;\r\nassert(isequal(num_sum(N,K),7))\r\n%%\r\nN=15;K=2;\r\nassert(isequal(num_sum(N,K),8))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":"2016-08-17T18:06:51.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-08-08T19:32:48.000Z","updated_at":"2025-12-05T13:02:15.000Z","published_at":"2016-08-08T19:34:19.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\u003eYou will be given two numbers, N and K. Write a MATLAB function that will determine how many different unique ways you can have K numbers add up to N. The numbers you use can be anything from 0-N, but no negatives and no fractions. For example, five can be the sum of three numbers in five different ways:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5+0+0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4+1+0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3+2+0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3+1+1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2+2+1\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\u003eOrder does not matter, so (5,0,0) is the same as (0,0,5) and (0,5,0). Therefore, the output of your function num_sum(5,3) should be 5. I don't need the different permutations, only how many there are. Good luck!\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":42920,"title":"Find the inverse permutation","description":"Given a permutation vector perm (a vector of n elements containing all the elements from 1 to n in some order), return the permutation vector invPerm such that perm(invPerm) is the a list of elements from 1 to n.","description_html":"\u003cp\u003eGiven a permutation vector perm (a vector of n elements containing all the elements from 1 to n in some order), return the permutation vector invPerm such that perm(invPerm) is the a list of elements from 1 to n.\u003c/p\u003e","function_template":"function invPerm = inversePermutation(perm)\r\n    invPerm = perm;\r\nend","test_suite":"%%\r\nfor permlength = 1:100\r\n    perm = randperm(permlength);\r\n    invPerm = inversePermutation(perm);\r\n    assert(isequal(perm(invPerm),1:permlength))\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":84115,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":71,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-08-18T08:57:39.000Z","updated_at":"2026-03-16T11:28:23.000Z","published_at":"2016-08-18T08:58:08.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eGiven a permutation vector perm (a vector of n elements containing all the elements from 1 to n in some order), return the permutation vector invPerm such that perm(invPerm) is the a list of elements from 1 to n.\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":43179,"title":"Red and green towers","description":"Frankie has a large number of wooden cubes, painted in red and green. He is building little towers with his cubes, by stacking them on top of each other.\r\n\r\nHe got bored after a while, so he introduced a rule: two red cubes may not be touching (see image).\r\n\r\n\u003c\u003c/matlabcentral/answers/uploaded_files/60747/color_towers.png\u003e\u003e\r\n\r\nGiven _n_ (the maximum number of cubes in a tower), determine the number _m_ of different towers that Frankie can build.\r\n\r\nExample: for _n_ = 2, he can make 5 towers, so _m_=5:\r\n\r\n# [Red];\r\n# [Green];\r\n# [Red, Green];\r\n# [Green, Red];\r\n# [Green, Green].\r\n\r\nYou may assume that the input is an integer greater than zero.","description_html":"\u003cp\u003eFrankie has a large number of wooden cubes, painted in red and green. He is building little towers with his cubes, by stacking them on top of each other.\u003c/p\u003e\u003cp\u003eHe got bored after a while, so he introduced a rule: two red cubes may not be touching (see image).\u003c/p\u003e\u003cimg src = \"/matlabcentral/answers/uploaded_files/60747/color_towers.png\"\u003e\u003cp\u003eGiven \u003ci\u003en\u003c/i\u003e (the maximum number of cubes in a tower), determine the number \u003ci\u003em\u003c/i\u003e of different towers that Frankie can build.\u003c/p\u003e\u003cp\u003eExample: for \u003ci\u003en\u003c/i\u003e = 2, he can make 5 towers, so \u003ci\u003em\u003c/i\u003e=5:\u003c/p\u003e\u003col\u003e\u003cli\u003e[Red];\u003c/li\u003e\u003cli\u003e[Green];\u003c/li\u003e\u003cli\u003e[Red, Green];\u003c/li\u003e\u003cli\u003e[Green, Red];\u003c/li\u003e\u003cli\u003e[Green, Green].\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eYou may assume that the input is an integer greater than zero.\u003c/p\u003e","function_template":"function m = towers(n)\r\n  m = 5;\r\nend","test_suite":"%%\r\nn = 1;\r\nm_correct = 2;\r\nassert(isequal(towers(n),m_correct))\r\n\r\n%%\r\nn = 2;\r\nm_correct = 5;\r\nassert(isequal(towers(n),m_correct))\r\n\r\n%%\r\nn = 3;\r\nm_correct = 10;\r\nassert(isequal(towers(n),m_correct))\r\n\r\n%%\r\nn = 15;\r\nm_correct = 4178;\r\nassert(isequal(towers(n),m_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":78934,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T21:26:31.000Z","updated_at":"2025-12-05T12:56:23.000Z","published_at":"2016-10-07T21:28:15.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\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"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\u003eFrankie has a large number of wooden cubes, painted in red and green. He is building little towers with his cubes, by stacking them on top of each other.\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\u003eHe got bored after a while, so he introduced a rule: two red cubes may not be touching (see image).\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:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\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\u003eGiven\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (the maximum number of cubes in a tower), determine the number\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of different towers that Frankie can build.\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\u003eExample: for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 2, he can make 5 towers, so\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=5:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[Red];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[Green];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[Red, Green];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[Green, Red];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[Green, Green].\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\u003eYou may assume that the input is an integer greater than zero.\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\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAGwCAYAAAAe1ALSAAAxqUlEQVR42u3dd7wV5Z0/8JtsdKNG3VdiojFqNGV/2Wh048aCYkdAiqLhJ+gaIZaYYkmiq4m6cS0xuoklJsYENRobUhWQqiBFQaSIBZWOUpQivbdnz8w5lwuIcNs5d87M+72vebl/GBnme5/n+X7mzjxTEQAAgMyocAkAAEAAAAAABAAAAEAAAAAABAAAAEAAAAAABAAAAEAAAAAABAAAAEAAAAAABAAAAEAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAAAQAAABAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAABAAAAAAAQAAAAQAAAAAAEAAAAQAAAAAAEAAAAQAAAAAAEAAAAQAAAAAAEAAAAQAAAAAAEAAAAQAAAAQAAAAAAEAAAAQAAAAAAEAAAA0mX+/Plh6tSpYcaMGY7CEV2P6LoIAABAprRq1Sp06NDBUTjatWsXHnzwwdTVuU2bNqGiosKxzRFdFwEAAMgUTeDHjygEpE0UbtT240d0XQQAAEAA0BQKAGotAAAAAoCmMD0BoHfueCSDR28BAAAQAKqaoRPafy08s7ZjeGL++Zk6+oVLMhcAQoYPAQAAEAAKx9GtDwoPzzg33DehTaaOKAQIAAKAAAAACAACgAAgAAgAAIAAIAAIAAKAAAAACAACgAAgAAgAAIAAIAAIAAKAAAAACAACgAAgAAgAAIAAIAAIAAKAAAAACAACgAAgAAgAAIAAIAAIAAIAAIAAIAAIAAIAAIAAIAAIAAIAACAACAACgAAgAAAAAoAAIAAIAAIAACAACAACgAAgAAAAAoAAIAAIAAIAACAACAACgAAgAAAAAoAAIAAIAAIAACAACAACgAAgAAAAAoAAIAAIAAIAACAACAACgAAgAAAAAoAAIAAIAAAAAoAAIAAIAAAAAoAAIAAIAACAACAACAACgAAAAAgAAoAAIAAIAACAACAACAACgAAAAAgAAoAAIAAIAACAACAACAACgAAAAAgAAoAAIAAIAACAACAACAACgAAAAAgAAoAAIAAIAACAACAACAACAACAACAACAACAACAACAACAACAAAgAAgAAoAAIAAAAAKAACAACAACAAAgAAgAAoAAIAAAAAKAACAACAACAAAgAAgAAoAAIAAAAAKAACAACAACAAAgAAgAAoAAIAAAAAKAACAACAACAAAgAAgAAoAAAAAgAAgAAoAAAAAgAAgAAoAAAAAIAAKAACAACAAAgAAgAAgAAoAAAAAIAAKAACAACAAAgAAgAAgAAoAAAAAIAAKAACAACAAAgAAgAAgAAoAAAAAIAAKAACAACAAAgAAgAAgAAoAAAAAIAAKAACAAAAAIAAKAACAAAAAIAAKAACAAAAACgAAgAAgAAgAAIAAIAAKAACAAAAACgAAgAAgAAgAAIAAIAAKAACAAAADlFQCO+/7BofPiC8JDuRCQpeOZtR0FAAFAAADYnhEjRoS2bdvGE6ajQ2jXrl148MEH1VqtUxMA9jlwj3B824PD0a0PzNRxYvtDMhcALo/+nhk8LhcAAGqmU6dOW02cjoq4MVRrtU5LAHBkJwA4BACAannkkUcsGBloFNQ6W7VWWwFArQUAAE2hplCtBQC1TplWrVqprQAAUPem8O5Xz4xfGIx20MjK0S9ckskAsMbLgpkIAJd7MVSt1VoAANhRU/g/fZuG+yeeY7vADNR6hkYhE01hB02hWqu1AAAgAAgAAoCmUK3VWq0FAEAAEAAEAI2CplCt1VqtBQBAABAABACNgqZQrdVarQUAQAAQAAQAjYKmUK3VWq0FAEAAEAAEAI2CplCt1VqtBQBAABAABACNgqZQrdVarQUAQAAQAAQAjYKmUK3VWq0FAEAAEAAEAI2CplCt1VoAABAABAABQKO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P/NMKktXkbWf1fGLp4XLX38wfP35H8e/VjxwwMXhqKHXhMffHxrmVk4mXhQsS0vXrQz3TO0TLwwH5Ooa1ffrg34cf3r+zWXvhbDewpy5sUyynHJKMnYFqalo69FPfWrn5475PIuiD9ztaFycd16uXuuTee633LLjc7/tttSWzYwFQOkcfPAnL7b9Evws95w5O/5NwMSJakt2jRix/XHRqlXyz/3BB7d/7hdemOqSCQAAlNbnP5+cXUFq6mtf+/i5R3dAIeu6ddt6XPz61+Vz7m+8sfW5n39+6sslAABQWjNn5l+WjRba6K76uHHldf5b7iLStat6QqXKrwX/9rfld+7Dh+f3+f/GNzJRKgEAgNJ75ZV8o7B0aXmef7QPevS9AGBrL7xQvucebVG6IBs7xwkAAACQIQIAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAACAAAAIAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAgAAACAAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAAAgAAAAAAIAAABkz/8BJfC3J3VZGjgAAAAASUVORK5CYII=\"}]}"},{"id":43091,"title":"Maximum sum from any 2 numbers with a variable number of inputs","description":"Given a variable number of inputs, combine any 2 numbers from the inputs and output the maximum sum the combinations can generate. For example:\r\n\r\n  x = 3;\r\n  y = 5;\r\n  z = 1;\r\n  y_correct = 8;","description_html":"\u003cp\u003eGiven a variable number of inputs, combine any 2 numbers from the inputs and output the maximum sum the combinations can generate. For example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 3;\r\ny = 5;\r\nz = 1;\r\ny_correct = 8;\r\n\u003c/pre\u003e","function_template":"function y = maxSumPair(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny = 5;\r\nz = 1;\r\ny_correct = 8;\r\nassert(isequal(maxSumPair(x,y,z),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(maxSumPair(x),y_correct))\r\n%%\r\nx = 1;\r\ny = 3;\r\ny_correct = 4;\r\nassert(isequal(maxSumPair(x,y),y_correct))\r\n%%\r\nx = 1;\r\ny = 1;\r\nz = 12;\r\np = 10;\r\ny_correct = 22;\r\nassert(isequal(maxSumPair(x,y,z,p),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":13865,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":60,"test_suite_updated_at":"2016-10-29T17:06:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-06T03:16:36.000Z","updated_at":"2025-12-17T20:24:25.000Z","published_at":"2016-10-06T03:16:36.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\u003eGiven a variable number of inputs, combine any 2 numbers from the inputs and output the maximum sum the combinations can generate. For example:\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[x = 3;\\ny = 5;\\nz = 1;\\ny_correct = 8;]]\u003e\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":43969,"title":"Sleeping Queens 1","description":"My youngest daughter received a card game named Sleeping Queens for Christmas this year, and has been playing it nearly non-stop since opening it.\r\n\r\nYou are dealt five cards, most of which have numbers 1-10 on them.  There are other cards, but for now we will just deal with the numbers.  You can discard cards in any of three different methods and draw that many new cards:\r\n\r\n* Individual cards, one at a time\r\n* Pairs of cards, but not three or four of a kind\r\n* Cards that make up an addition problem.\r\n\r\nWrite a MATLAB script that will tell you how how many different ways you can discard cards in your hand.\r\n\r\nFor example, if your hand had the cards [1 2 2 4 9], you could discard\r\n\r\n* Any of the cards individually  (5)\r\n* The pair of 2s  (1)\r\n* [2 2 4] because 2+2=4  (1)\r\n* [1 2 2 4 9] because 1+2+2+4=9  (1)\r\n\r\nso your script would output 8.  Likewise, a hand of [1 2 2 2 6] would allow you discard cards 9 different ways:\r\n\r\n* Any of the cards individually  (5)\r\n* Any of the three different pairs of 2s  (3)\r\n* [2 2 2 6] because 2+2+2=6  (1)\r\n\r\nSo the output of your script for [1 2 2 2 6] should be 9.  We don't need to know what the possible combinations are to discard just yet; we just need to know how many there are.  Good luck, and happy hunting!","description_html":"\u003cp\u003eMy youngest daughter received a card game named Sleeping Queens for Christmas this year, and has been playing it nearly non-stop since opening it.\u003c/p\u003e\u003cp\u003eYou are dealt five cards, most of which have numbers 1-10 on them.  There are other cards, but for now we will just deal with the numbers.  You can discard cards in any of three different methods and draw that many new cards:\u003c/p\u003e\u003cul\u003e\u003cli\u003eIndividual cards, one at a time\u003c/li\u003e\u003cli\u003ePairs of cards, but not three or four of a kind\u003c/li\u003e\u003cli\u003eCards that make up an addition problem.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWrite a MATLAB script that will tell you how how many different ways you can discard cards in your hand.\u003c/p\u003e\u003cp\u003eFor example, if your hand had the cards [1 2 2 4 9], you could discard\u003c/p\u003e\u003cul\u003e\u003cli\u003eAny of the cards individually  (5)\u003c/li\u003e\u003cli\u003eThe pair of 2s  (1)\u003c/li\u003e\u003cli\u003e[2 2 4] because 2+2=4  (1)\u003c/li\u003e\u003cli\u003e[1 2 2 4 9] because 1+2+2+4=9  (1)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eso your script would output 8.  Likewise, a hand of [1 2 2 2 6] would allow you discard cards 9 different ways:\u003c/p\u003e\u003cul\u003e\u003cli\u003eAny of the cards individually  (5)\u003c/li\u003e\u003cli\u003eAny of the three different pairs of 2s  (3)\u003c/li\u003e\u003cli\u003e[2 2 2 6] because 2+2+2=6  (1)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSo the output of your script for [1 2 2 2 6] should be 9.  We don't need to know what the possible combinations are to discard just yet; we just need to know how many there are.  Good luck, and happy hunting!\u003c/p\u003e","function_template":"function y = Sleeping(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [5 6 7 8 9];y_correct = 5;\r\nassert(isequal(Sleeping(x),y_correct))\r\n%%\r\nx = [1 5 3 2 4];y_correct = 9;\r\nassert(isequal(Sleeping(x),y_correct))\r\n%%\r\nx = [2 4 8 4 2];y_correct = 12;\r\nassert(isequal(Sleeping(x),y_correct))\r\n%%\r\nx = [1 1 1 2 1];y_correct = 17;\r\nassert(isequal(Sleeping(x),y_correct))\r\n%%\r\nx = [3 6 5 1 8];y_correct = 7;\r\nassert(isequal(Sleeping(x),y_correct))\r\n%%\r\nassert(isequal(Sleeping([1 6 1 7 8]),11))\r\n%%\r\nassert(isequal(Sleeping([2 3 3 1 5]),10))","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":"2016-12-27T20:04:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-12-27T19:51:49.000Z","updated_at":"2026-01-18T21:43:45.000Z","published_at":"2016-12-27T20:04:57.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\u003eMy youngest daughter received a card game named Sleeping Queens for Christmas this year, and has been playing it nearly non-stop since opening it.\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\u003eYou are dealt five cards, most of which have numbers 1-10 on them. There are other cards, but for now we will just deal with the numbers. You can discard cards in any of three different methods and draw that many new cards:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIndividual cards, one at a time\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePairs of cards, but not three or four of a kind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCards that make up an addition problem.\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\u003eWrite a MATLAB script that will tell you how how many different ways you can discard cards in your hand.\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\u003eFor example, if your hand had the cards [1 2 2 4 9], you could discard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny of the cards individually (5)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe pair of 2s (1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[2 2 4] because 2+2=4 (1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 2 2 4 9] because 1+2+2+4=9 (1)\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\u003eso your script would output 8. Likewise, a hand of [1 2 2 2 6] would allow you discard cards 9 different ways:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny of the cards individually (5)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny of the three different pairs of 2s (3)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[2 2 2 6] because 2+2+2=6 (1)\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\u003eSo the output of your script for [1 2 2 2 6] should be 9. We don't need to know what the possible combinations are to discard just yet; we just need to know how many there are. Good luck, and happy hunting!\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":44082,"title":"Recycled Numbers (CodeJam Qualification Round 2012)","description":"Let's say a pair of distinct positive integers ( _n_ , _m_ ) is recycled if you can obtain _m_ by moving some digits \r\nfrom the back of _n_ to the front without changing their order. For example, (12345, 34512) is a recycled pair since you can obtain 34512 by moving 345 from the end of 12345 to the front. Note that _n_ and _m_ must have the same number of digits in order to be a recycled pair. Neither _n_ nor _m_ can have leading zeros.\r\n\r\nGiven integers *A* and *B* with the same number of digits and no leading zeros, how many *distinct* recycled pairs ( _n_ , _m_ ) are there with *A* ≤ _n_ \u003c _m_ ≤ *B* ? \r\n\r\nBe careful, it is more tricky than you might first think...","description_html":"\u003cp\u003eLet's say a pair of distinct positive integers ( \u003ci\u003en\u003c/i\u003e , \u003ci\u003em\u003c/i\u003e ) is recycled if you can obtain \u003ci\u003em\u003c/i\u003e by moving some digits \r\nfrom the back of \u003ci\u003en\u003c/i\u003e to the front without changing their order. For example, (12345, 34512) is a recycled pair since you can obtain 34512 by moving 345 from the end of 12345 to the front. Note that \u003ci\u003en\u003c/i\u003e and \u003ci\u003em\u003c/i\u003e must have the same number of digits in order to be a recycled pair. Neither \u003ci\u003en\u003c/i\u003e nor \u003ci\u003em\u003c/i\u003e can have leading zeros.\u003c/p\u003e\u003cp\u003eGiven integers \u003cb\u003eA\u003c/b\u003e and \u003cb\u003eB\u003c/b\u003e with the same number of digits and no leading zeros, how many \u003cb\u003edistinct\u003c/b\u003e recycled pairs ( \u003ci\u003en\u003c/i\u003e , \u003ci\u003em\u003c/i\u003e ) are there with \u003cb\u003eA\u003c/b\u003e ≤ \u003ci\u003en\u003c/i\u003e \u0026lt; \u003ci\u003em\u003c/i\u003e ≤ \u003cb\u003eB\u003c/b\u003e ?\u003c/p\u003e\u003cp\u003eBe careful, it is more tricky than you might first think...\u003c/p\u003e","function_template":"function y = recycled_numbers(a,b)\r\n  y = x;\r\nend","test_suite":"%%\r\na=1;\r\nb=9;\r\ny_correct = 0;\r\nassert(isequal(recycled_numbers(a,b),y_correct))\r\n%%\r\na=10;\r\nb=40;\r\ny_correct = 3;\r\nassert(isequal(recycled_numbers(a,b),y_correct))\r\n%%\r\na=1111;\r\nb=2222;\r\ny_correct = 287 ; %:)\r\nassert(isequal(recycled_numbers(a,b),y_correct))\r\n%%\r\na=21;\r\nb=31;\r\ny_correct = 0;\r\nassert(isequal(recycled_numbers(a,b),y_correct))\r\n%%\r\na=1;\r\nb=9;\r\ny_correct = 0;\r\nassert(isequal(recycled_numbers(a,b),y_correct))\r\n%%\r\na=104;\r\nb=989;\r\nassert(isequal(recycled_numbers(a,b),781))\r\n%%\r\na=10;\r\nb=99;\r\ny = 36;\r\nassert(isequal(recycled_numbers(a,b),y))\r\n%%\r\nassert(isequal(recycled_numbers(100,999),801))\r\n%%\r\na=1000;\r\nb=9999;\r\ny_correct = 12060;\r\nassert(isequal(recycled_numbers(a,b),y_correct))\r\n%%\r\nb=484;\r\na=954;\r\nassert(isequal(recycled_numbers(b,a),203))\r\n%%\r\na=159887;\r\nb=195662;\r\ncorrect = 2058;\r\nassert(isequal(recycled_numbers(a,b),correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":2,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":"2017-03-09T12:41:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-03-09T11:10:22.000Z","updated_at":"2025-12-05T12:51:14.000Z","published_at":"2017-03-09T11:21:54.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\u003eLet's say a pair of distinct positive integers (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) is recycled if you can obtain\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e by moving some digits from the back of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the front without changing their order. For example, (12345, 34512) is a recycled pair since you can obtain 34512 by moving 345 from the end of 12345 to the front. Note that\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e must have the same number of digits in order to be a recycled pair. Neither\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e can have leading zeros.\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\u003eGiven integers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with the same number of digits and no leading zeros, how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edistinct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e recycled pairs (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) are there with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ≤\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026lt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ≤\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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:t\u003eBe careful, it is more tricky than you might first think...\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":44456,"title":"Sum of combinations","description":"Input:  *X = 40*, *Y = [40 20 10 4]*\r\n\r\nOutput: *Z = [1 0 0 0; 0 2 0 0; 0 1 2 0; 0 1 1 3; 0 1 0 5; 0 0 4 0; 0 0 3 3; 0 0 2 5; 0 0 1 8; 0 0 0 10]*\r\n\r\nDescription: \r\n\r\n* Z(1,:)*Y' \u003e=40; (40*1+0+0+0)=40\r\n* Z(4,:)*Y' \u003e=40; (0+20*1+10*1+4*3)\u003e40 (but minimum), and so on...\r\n\r\n* Z should not contain any fraction.\r\n* Z should contain all possible combinations.\r\n* Input Y is always sorted","description_html":"\u003cp\u003eInput:  \u003cb\u003eX = 40\u003c/b\u003e, \u003cb\u003eY = [40 20 10 4]\u003c/b\u003e\u003c/p\u003e\u003cp\u003eOutput: \u003cb\u003eZ = [1 0 0 0; 0 2 0 0; 0 1 2 0; 0 1 1 3; 0 1 0 5; 0 0 4 0; 0 0 3 3; 0 0 2 5; 0 0 1 8; 0 0 0 10]\u003c/b\u003e\u003c/p\u003e\u003cp\u003eDescription:\u003c/p\u003e\u003cul\u003e\u003cli\u003eZ(1,:)*Y' \u0026gt;=40; (40*1+0+0+0)=40\u003c/li\u003e\u003cli\u003eZ(4,:)*Y' \u0026gt;=40; (0+20*1+10*1+4*3)\u0026gt;40 (but minimum), and so on...\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003eZ should not contain any fraction.\u003c/li\u003e\u003cli\u003eZ should contain all possible combinations.\u003c/li\u003e\u003cli\u003eInput Y is always sorted\u003c/li\u003e\u003c/ul\u003e","function_template":"function z = your_fcn_name(x,y)\r\nend","test_suite":"%%\r\nx = 40;\r\ny = [40 20 10 4];\r\nz_correct =  [1 0 0 0; 0 2 0 0; 0 1 2 0; 0 1 1 3; 0 1 0 5; 0 0 4 0; 0 0 3 3; 0 0 2 5; 0 0 1 8; 0 0 0 10];\r\nassert(isequal(your_fcn_name(x,y),z_correct))\r\n\r\n%%\r\nx = 13;\r\ny = [40 20 10 4];\r\nz_correct =  [1 0 0 0; 0 1 0 0; 0 0 2 0; 0 0 1 1; 0 0 0 4];\r\nassert(isequal(your_fcn_name(x,y),z_correct))\r\n\r\n%%\r\nx = 19;\r\ny = [10 4];\r\nz_correct =  [2 0; 1 3; 0 5];\r\nassert(isequal(your_fcn_name(x,y),z_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":14921,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-17T05:04:58.000Z","updated_at":"2025-12-05T12:30:05.000Z","published_at":"2017-12-17T05:07:36.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\u003eInput: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eX = 40\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY = [40 20 10 4]\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\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eZ = [1 0 0 0; 0 2 0 0; 0 1 2 0; 0 1 1 3; 0 1 0 5; 0 0 4 0; 0 0 3 3; 0 0 2 5; 0 0 1 8; 0 0 0 10]\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\u003eDescription:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eZ(1,:)*Y' \u0026gt;=40; (40*1+0+0+0)=40\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eZ(4,:)*Y' \u0026gt;=40; (0+20*1+10*1+4*3)\u0026gt;40 (but minimum), and so on...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eZ should not contain any fraction.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eZ should contain all possible combinations.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput Y is always sorted\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":986,"title":"Penny Flipping: Reverse subsets of a sequence of coins until you recover the original configuration","description":"The original Penny Flipping Problem (PF-1) starts with a stack of N pennies arranged with all the coins heads up. The first operation is to flip the top coin. The second operation is to take the top two coins, invert this substack, and replace the substack on the main stack. The Nth operation is to invert the entire stack. The (N+1) operation is the same as the first operation.  This sequence of reversals continues until the stack is returned to an all heads up configuration. Here is the sequence for N=3, with 0 corresponding to heads up and 1 corresponding to heads down:\r\n\r\n 0 1 2 3 4 5 6 7 8 9\r\n -------------------\r\n 0 1 1 1 0 0 1 0 1 0\r\n 0 0 0 1 1 1 0 0 1 0\r\n 0 0 0 0 0 0 1 1 1 0\r\n\r\nNine operations are required to regain the all heads up configuration for N=3. The problem for PF-1 is to find the number of operations to regain all heads up, so PF-1(3) = 9.\r\n\r\n*Note:* Inverting the substack performs two distinct operations on the coins. The orientations of the coins are reversed, and the positions of the coins in the substack are also exchanged across the middle of the substack.\r\n\r\nThe alternating Penny Flipping Problem (PF-2) is the same as for PF-1 except that successive operations alternate from the top and the bottom of the stack, instead of just from the top, as with PF-1. Here is the PF-2 sequence for N=3:\r\n\r\n 0 1 2 3 \r\n -------\r\n 0 1 1 0 \r\n 0 0 1 0 \r\n 0 0 1 0 \r\n\r\nSo PF-2(3) = 3.\r\n\r\nWrite a function that returns PF-2(N), for N a positive integer.\r\n\r\nI have posted a plot of PF-2 for N=1:50 at this Google link:\r\n\r\n\u003chttps://picasaweb.google.com/115436881097292918347/Matlab#5798055972168308562 coinFlipAlt Plot\u003e\r\n","description_html":"\u003cp\u003eThe original Penny Flipping Problem (PF-1) starts with a stack of N pennies arranged with all the coins heads up. The first operation is to flip the top coin. The second operation is to take the top two coins, invert this substack, and replace the substack on the main stack. The Nth operation is to invert the entire stack. The (N+1) operation is the same as the first operation.  This sequence of reversals continues until the stack is returned to an all heads up configuration. Here is the sequence for N=3, with 0 corresponding to heads up and 1 corresponding to heads down:\u003c/p\u003e\u003cpre\u003e 0 1 2 3 4 5 6 7 8 9\r\n -------------------\r\n 0 1 1 1 0 0 1 0 1 0\r\n 0 0 0 1 1 1 0 0 1 0\r\n 0 0 0 0 0 0 1 1 1 0\u003c/pre\u003e\u003cp\u003eNine operations are required to regain the all heads up configuration for N=3. The problem for PF-1 is to find the number of operations to regain all heads up, so PF-1(3) = 9.\u003c/p\u003e\u003cp\u003e\u003cb\u003eNote:\u003c/b\u003e Inverting the substack performs two distinct operations on the coins. The orientations of the coins are reversed, and the positions of the coins in the substack are also exchanged across the middle of the substack.\u003c/p\u003e\u003cp\u003eThe alternating Penny Flipping Problem (PF-2) is the same as for PF-1 except that successive operations alternate from the top and the bottom of the stack, instead of just from the top, as with PF-1. Here is the PF-2 sequence for N=3:\u003c/p\u003e\u003cpre\u003e 0 1 2 3 \r\n -------\r\n 0 1 1 0 \r\n 0 0 1 0 \r\n 0 0 1 0 \u003c/pre\u003e\u003cp\u003eSo PF-2(3) = 3.\u003c/p\u003e\u003cp\u003eWrite a function that returns PF-2(N), for N a positive integer.\u003c/p\u003e\u003cp\u003eI have posted a plot of PF-2 for N=1:50 at this Google link:\u003c/p\u003e\u003cp\u003e\u003ca href=\"https://picasaweb.google.com/115436881097292918347/Matlab#5798055972168308562\"\u003ecoinFlipAlt Plot\u003c/a\u003e\u003c/p\u003e","function_template":"function count = coinFlipAlt(n)\r\n  count = 1;\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 2;\r\nassert(isequal(coinFlipAlt(n),y_correct))\r\n%%\r\nn = 3;\r\ny_correct = 3;\r\nassert(isequal(coinFlipAlt(n),y_correct))\r\n%%\r\nn = 10;\r\ny_correct = 295;\r\nassert(isequal(coinFlipAlt(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":7,"created_by":6970,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2012-10-10T17:03:47.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-10T16:24:20.000Z","updated_at":"2025-12-05T12:23:57.000Z","published_at":"2012-10-10T17:03: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\u003eThe original Penny Flipping Problem (PF-1) starts with a stack of N pennies arranged with all the coins heads up. The first operation is to flip the top coin. The second operation is to take the top two coins, invert this substack, and replace the substack on the main stack. The Nth operation is to invert the entire stack. The (N+1) operation is the same as the first operation. This sequence of reversals continues until the stack is returned to an all heads up configuration. Here is the sequence for N=3, with 0 corresponding to heads up and 1 corresponding to heads down:\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[ 0 1 2 3 4 5 6 7 8 9\\n -------------------\\n 0 1 1 1 0 0 1 0 1 0\\n 0 0 0 1 1 1 0 0 1 0\\n 0 0 0 0 0 0 1 1 1 0]]\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:t\u003eNine operations are required to regain the all heads up configuration for N=3. The problem for PF-1 is to find the number of operations to regain all heads up, so PF-1(3) = 9.\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\u003eNote:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Inverting the substack performs two distinct operations on the coins. The orientations of the coins are reversed, and the positions of the coins in the substack are also exchanged across the middle of the substack.\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 alternating Penny Flipping Problem (PF-2) is the same as for PF-1 except that successive operations alternate from the top and the bottom of the stack, instead of just from the top, as with PF-1. Here is the PF-2 sequence for N=3:\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[ 0 1 2 3 \\n -------\\n 0 1 1 0 \\n 0 0 1 0 \\n 0 0 1 0]]\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:t\u003eSo PF-2(3) = 3.\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\u003eWrite a function that returns PF-2(N), for N a positive integer.\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\u003eI have posted a plot of PF-2 for N=1:50 at this Google link:\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:hyperlink w:docLocation=\\\"https://picasaweb.google.com/115436881097292918347/Matlab#5798055972168308562\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecoinFlipAlt Plot\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44719,"title":"Penny Distribution Machine","description":"A machine consists of a row of boxes. To start, one places N pennies in the leftmost box. The machine then redistributes the pennies as follows:\r\n\r\nOn each iteration, it replaces a pair of pennies in one box with a single penny in the next box to the right. The iterations stop when there is no box with more than one coin. For example, the figure below shows the working of the machine in distributing nine pennies by always selecting a pair of pennies in the leftmost box with at least two coins.\r\n\r\n  Itr 0:   9  0  0  0        \r\n  Itr 1:   7  1  0  0 \r\n  Itr 2:   5  2  0  0  \r\n  Itr 3:   3  3  0  0  \r\n  Itr 4:   1  4  0  0   \r\n  Itr 5:   1  2  1  0   \r\n  Itr 6:   1  0  2  0   \r\n  Itr 7:   1  0  0  1  \r\n\r\nDetermine the number of boxes and iterations needed by the machine to distribute N pennies. From the example above, the machine requires four boxes and seven iterations to distribute nine pennies.\r\n  ","description_html":"\u003cp\u003eA machine consists of a row of boxes. To start, one places N pennies in the leftmost box. The machine then redistributes the pennies as follows:\u003c/p\u003e\u003cp\u003eOn each iteration, it replaces a pair of pennies in one box with a single penny in the next box to the right. The iterations stop when there is no box with more than one coin. For example, the figure below shows the working of the machine in distributing nine pennies by always selecting a pair of pennies in the leftmost box with at least two coins.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eItr 0:   9  0  0  0        \r\nItr 1:   7  1  0  0 \r\nItr 2:   5  2  0  0  \r\nItr 3:   3  3  0  0  \r\nItr 4:   1  4  0  0   \r\nItr 5:   1  2  1  0   \r\nItr 6:   1  0  2  0   \r\nItr 7:   1  0  0  1  \r\n\u003c/pre\u003e\u003cp\u003eDetermine the number of boxes and iterations needed by the machine to distribute N pennies. From the example above, the machine requires four boxes and seven iterations to distribute nine pennies.\u003c/p\u003e","function_template":"function [box, itr] = PDMachine(N)\r\n \r\nend","test_suite":"%%\r\nN = 1;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,1) \u0026 isequal(itr,0))\r\n\r\n%%\r\nN = 2;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,2) \u0026 isequal(itr,1))\r\n\r\n%%\r\nN = 3;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,2) \u0026 isequal(itr,1))\r\n\r\n%%\r\nN = 5;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,3) \u0026 isequal(itr,3))\r\n\r\n%%\r\nN = 10;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,4) \u0026 isequal(itr,8))\r\n\r\n%%\r\nN = 19;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,5) \u0026 isequal(itr,16))\r\n\r\n%%\r\nN = 25;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,5) \u0026 isequal(itr,22))\r\n\r\n%%\r\nN = 50;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,6) \u0026 isequal(itr,47))\r\n\r\n%%\r\nN = 100;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,7) \u0026 isequal(itr,97))\r\n\r\n%%\r\nN = 777;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,10) \u0026 isequal(itr,773))\r\n\r\n%%\r\nN = 1234;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,11) \u0026 isequal(itr,1229))\r\n\r\n%%\r\nN = 5000;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,13) \u0026 isequal(itr,4995))\r\n\r\n%%\r\nN = 9999;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,14) \u0026 isequal(itr,9991))\r\n\r\n%%\r\nN = 100000;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,17) \u0026 isequal(itr,99994))\r\n\r\n%%\r\nN = 1234567;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,21) \u0026 isequal(itr,1234556))\r\n\r\n%%\r\nN = 12345678;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,24) \u0026 isequal(itr,12345666))\r\n\r\n%%\r\nN = 987654321;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,30) \u0026 isequal(itr,987654304))\r\n\r\n%%\r\nN = 1234567890;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,31) \u0026 isequal(itr,1234567878))\r\n\r\n%%\r\nN = 9876543210;\r\n[box, itr] = PDMachine(N);\r\nassert(isequal(box,34) \u0026 isequal(itr,9876543195))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":178544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2018-09-18T17:45:21.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-08-05T02:30:50.000Z","updated_at":"2025-12-05T12:14:33.000Z","published_at":"2018-08-05T03:02:52.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\u003eA machine consists of a row of boxes. To start, one places N pennies in the leftmost box. The machine then redistributes the pennies as follows:\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\u003eOn each iteration, it replaces a pair of pennies in one box with a single penny in the next box to the right. The iterations stop when there is no box with more than one coin. For example, the figure below shows the working of the machine in distributing nine pennies by always selecting a pair of pennies in the leftmost box with at least two coins.\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[Itr 0:   9  0  0  0        \\nItr 1:   7  1  0  0 \\nItr 2:   5  2  0  0  \\nItr 3:   3  3  0  0  \\nItr 4:   1  4  0  0   \\nItr 5:   1  2  1  0   \\nItr 6:   1  0  2  0   \\nItr 7:   1  0  0  1]]\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:t\u003eDetermine the number of boxes and iterations needed by the machine to distribute N pennies. From the example above, the machine requires four boxes and seven iterations to distribute nine pennies.\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\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}