{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":60686,"title":"Diagonal Product of A Square Matrix","description":"For a matrix A, calculate the product of its diagonal elements. \r\n* Assume all input matrices are square \u0026 corresponding elements are integers\r\n* Keep in mind that we are looking for the product of the diagonal elements, not the trace (sum)!","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: 81px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 40.5px; transform-origin: 407px 40.5px; vertical-align: baseline; \"\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-collapse: preserve; 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: 191.75px 8px; transform-origin: 191.75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor a matrix A, calculate the product of its diagonal elements. \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-collapse: preserve; 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: 241.958px 8px; transform-origin: 241.958px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e* Assume all input matrices are square \u0026amp; corresponding elements are integers\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-collapse: preserve; 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: 296px 8px; transform-origin: 296px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e* Keep in mind that we are looking for the product of the diagonal elements, not the trace (sum)!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = diag_prod(A)\r\n  y = A;\r\nend","test_suite":"%%\r\nA = [1 2; 3 4];\r\ny_correct = 4; % 1 x 4\r\nassert(isequal(diag_prod(A),y_correct))\r\n\r\n%%\r\nA = [1 5 6; 20 4 3; 2 101 -4];\r\ny_correct = -16; % 1 x 4 x -4\r\nassert(isequal(diag_prod(A),y_correct))\r\n\r\n%%\r\nA = zeros(20);\r\ny_correct = 0; % 0 x 0 x 0...\r\nassert(isequal(diag_prod(A),y_correct))\r\n\r\n%% \r\nA = ones(100);\r\ny_correct = 1;\r\nassert(isequal(diag_prod(A),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4585291,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-08-06T14:27:36.000Z","updated_at":"2026-03-21T09:10:43.000Z","published_at":"2024-08-06T14:27:36.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eFor a matrix A, calculate the product of its diagonal elements. \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\u003e* Assume all input matrices are square \u0026amp; corresponding elements are integers\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\u003e* Keep in mind that we are looking for the product of the diagonal elements, not the trace (sum)!\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":44634,"title":"Basic matrix operations using standard MATLAB commands","description":"Create the matrix:\r\n\r\n 1.0e+15 *\r\n\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\r\n\r\nFind the row vector of all column means\r\n\r\nHint: Use _logspace_ to create the matrix. Avoid looking at the test suite before writing a solution","description_html":"\u003cp\u003eCreate the matrix:\u003c/p\u003e\u003cpre\u003e 1.0e+15 *\u003c/pre\u003e\u003cpre\u003e    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\u003c/pre\u003e\u003cp\u003eFind the row vector of all column means\u003c/p\u003e\u003cp\u003eHint: Use \u003ci\u003elogspace\u003c/i\u003e to create the matrix. Avoid looking at the test suite before writing a solution\u003c/p\u003e","function_template":"function y = matrix_ls_means()\r\n  y = x;\r\nend","test_suite":"%%\r\ny_correct = mean([logspace(1,5,5);logspace(6,10,5);logspace(11,15,5)]);\r\nassert(isequal(matrix_ls_means(),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-05-09T05:37:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T05:32:41.000Z","updated_at":"2026-02-17T08:19:25.000Z","published_at":"2018-05-09T05:35:49.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\u003eCreate the matrix:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1.0e+15 *\\n\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0001    0.0010    0.0100    0.1000    1.0000]]\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\u003eFind the row vector of all column means\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\u003eHint: Use\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\u003elogspace\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to create the matrix. Avoid looking at the test suite before writing a solution\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":44546,"title":"Calculating the total earnings of a factory","description":"The row vector, prods contains the number of various products manufactured per hour. The second row vector, prices holds values for the corresponding item prices they sell the given product for. Given the factory generates operates on a 6-day work week and two 8-hour long shifts per day, find the total earnings.","description_html":"\u003cp\u003eThe row vector, prods contains the number of various products manufactured per hour. The second row vector, prices holds values for the corresponding item prices they sell the given product for. Given the factory generates operates on a 6-day work week and two 8-hour long shifts per day, find the total earnings.\u003c/p\u003e","function_template":"function earn = earnings(rate, price)\r\n    earn= (); % use your basic knowledge of matrix multiplication\r\nend","test_suite":"%%\r\nrate = [2,5,4];\r\nprice = [8,3,1];\r\ny_correct = 3360;\r\nassert(isequal(earnings(rate,price),3360))\r\n%%\r\nrate = [1,4];\r\nprice = [2,1];\r\ny_correct = 576;\r\nassert(isequal(earnings(rate,price),576))\r\n%%\r\nrate = [6 6 2 3 2 8];\r\nprice = [3 2 4 8 9 5];\r\ny_correct = 11520;\r\nassert(isequal(earnings(rate,price),11520))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-03-31T09:16:35.000Z","updated_at":"2026-02-11T11:25:03.000Z","published_at":"2018-03-31T09:16:35.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\u003eThe row vector, prods contains the number of various products manufactured per hour. The second row vector, prices holds values for the corresponding item prices they sell the given product for. Given the factory generates operates on a 6-day work week and two 8-hour long shifts per day, find the total earnings.\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":59244,"title":"nxn matrix with elements from 1:n^2","description":"input n defines the dimension of a square matrix to be filled from 1 to n^2  with 1 in upper left corner and n^2 in bottom right corner, numbers increasing from left to right across rows\r\nexamples:\r\nn=1\r\n1\r\nn=2\r\n1 2\r\n3 4\r\nn=5\r\n1  2  3  4  5\r\n6  7  8  9  10\r\n11 12 13 14 15 \r\n16 17 18 19 20 \r\n21 22 23 24 25\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 388.455px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 194.227px; transform-origin: 407.5px 194.227px; vertical-align: baseline; \"\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: 384.5px 21px; text-align: left; transform-origin: 384.5px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003einput n defines the dimension of a square matrix to be filled from 1 to n^2  with 1 in upper left corner and n^2 in bottom right corner, numbers increasing from left to right across rows\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eexamples:\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en=1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4318px; 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: 404.5px 10.2159px; transform-origin: 404.5px 10.2159px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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; text-wrap: 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en=2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8636px; 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: 404.5px 20.4318px; transform-origin: 404.5px 20.4318px; 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.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e3 4\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en=5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 102.159px; 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: 404.5px 51.0795px; transform-origin: 404.5px 51.0795px; 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.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1  2  3  4  5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e6  7  8  9  10\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e11 12 13 14 15 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e16 17 18 19 20 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e21 22 23 24 25\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = squarematrix(n)\r\nmax=(n)^2;\r\nn=[];\r\nfor i1=1:max^(1/2):max\r\n    n=[n;i1:i1+(sf*f-1)];\r\nend\r\nend","test_suite":"%%\r\nn=1;\r\ny_correct=1;\r\nassert(isequal(squarematrix(n),y_correct))\r\n\r\n%%\r\nn=2;\r\ny_correct=[1 2;3 4];\r\nassert(isequal(squarematrix(n),y_correct))\r\n\r\n%%\r\nn=3;\r\ny_correct=[1 2 3;4 5 6;7 8 9];\r\nassert(isequal(squarematrix(n),y_correct))\r\n\r\n%%\r\nn=7;\r\ny_correct=[1     2     3     4     5     6     7;\r\n           8     9     10    11    12    13    14;\r\n           15    16    17    18    19    20    21;\r\n           22    23    24    25    26    27    28;\r\n           29    30    31    32    33    34    35;\r\n           36    37    38    39    40    41    42;\r\n           43    44    45    46    47    48    49];\r\nassert(isequal(squarematrix(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3499438,"edited_by":3499438,"edited_at":"2024-05-23T18:24:13.000Z","deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-11-30T21:12:27.000Z","updated_at":"2026-03-09T18:51:53.000Z","published_at":"2023-11-30T21:12:27.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003einput n defines the dimension of a square matrix to be filled from 1 to n^2  with 1 in upper left corner and n^2 in bottom right corner, numbers increasing from left to right across rows\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\u003eexamples:\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=1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1]]\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\u003en=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1 2\\n3 4]]\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\u003en=5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1  2  3  4  5\\n6  7  8  9  10\\n11 12 13 14 15 \\n16 17 18 19 20 \\n21 22 23 24 25]]\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\u003e\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":42346,"title":"Create a Matrix of Zeros","description":"Given an input x, create a square matrix y of zeros with x rows and x columns.","description_html":"\u003cp\u003eGiven an input x, create a square matrix y of zeros with x rows and x columns.\u003c/p\u003e","function_template":"function y = matrix_zeros(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;\r\ny_correct = [ ...\r\n     0     0  \r\n     0     0  ];\r\nassert(isequal(matrix_zeros(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = [ ...\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0];\r\nassert(isequal(matrix_zeros(x),y_correct))\r\n\r\n%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(matrix_zeros(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":44605,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":647,"test_suite_updated_at":"2015-06-17T18:04:48.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-06-01T01:15:52.000Z","updated_at":"2026-02-15T15:03:06.000Z","published_at":"2015-06-01T01:16:06.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 an input x, create a square matrix y of zeros with x rows and x columns.\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":44401,"title":"Vertical matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 8  9  3  9\r\n      9  6  5  2\r\n      2  1  9  9\r\n  \r\n  y = 2  1  3  2\r\n      8  6  5  9\r\n      9  9  9  9\r\n      9  9  9  9\r\n      8  6  5  9\r\n      2  1  3  2","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 8  9  3  9\r\n    9  6  5  2\r\n    2  1  9  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 2  1  3  2\r\n    8  6  5  9\r\n    9  9  9  9\r\n    9  9  9  9\r\n    8  6  5  9\r\n    2  1  3  2\r\n\u003c/pre\u003e","function_template":"function y = upAndDown(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0;0];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = zeros(10);\r\nx(7,4) = 1;\r\ny_correct = zeros(20,10);\r\ny_correct(10:11,4) = [1;1];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 4 3 2; 1 4 3 2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [8  9  3  9; 9  6  5  2; 2  1  9  9];\r\ny_correct = [2  1  3  2; 8  6  5  9; 9  9  9  9;\r\n             9  9  9  9; 8  6  5  9; 2  1  3  2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x; x];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x; flipud(x)];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nc = [1:3,3:-1:1]';\r\ny_correct = [c,c+3,c+6];\r\nassert(isequal(upAndDown(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":340,"test_suite_updated_at":"2018-05-13T07:02:36.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-11-12T07:18:04.000Z","updated_at":"2026-02-11T19:50:48.000Z","published_at":"2017-11-12T07:31:05.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 matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\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:\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 = 8  9  3  9\\n    9  6  5  2\\n    2  1  9  9\\n\\ny = 2  1  3  2\\n    8  6  5  9\\n    9  9  9  9\\n    9  9  9  9\\n    8  6  5  9\\n    2  1  3  2]]\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":43272,"title":"Implement zero-based indexing for Matrices","description":"Given an input vector and position (which is zero based) output the value \r\n\r\nExample:\r\n\r\nx = [1 2; 4 5] pos = [0 1] value = 5\r\n\r\nx = [1 2 3 4 5; 6 7 8 9 0] pos = [1 3] value = 9","description_html":"\u003cp\u003eGiven an input vector and position (which is zero based) output the value\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ex = [1 2; 4 5] pos = [0 1] value = 5\u003c/p\u003e\u003cp\u003ex = [1 2 3 4 5; 6 7 8 9 0] pos = [1 3] value = 9\u003c/p\u003e","function_template":"function y = zeroBasedMN(x,pos)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4 5];\r\npos  = [0 2]\r\ny_correct = 4;\r\nassert(isequal(zeroBasedMN(x,pos),y_correct))\r\n%%\r\nx = [1 2 3 4 5; 6 7 8 9 0];\r\npos = [1 3];\r\ny_correct = 9\r\nassert(isequal(zeroBasedMN(x,pos),y_correct))","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":13865,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2016-10-29T16:26:00.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-09T05:56:33.000Z","updated_at":"2026-03-31T13:17:53.000Z","published_at":"2016-10-09T05:56:33.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 an input vector and position (which is zero based) output the value\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = [1 2; 4 5] pos = [0 1] value = 5\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\u003ex = [1 2 3 4 5; 6 7 8 9 0] pos = [1 3] value = 9\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":44613,"title":"Find NaNs in the matrix","description":"Return 1s wherever there is a NaN in the input matrix","description_html":"\u003cp\u003eReturn 1s wherever there is a NaN in the input matrix\u003c/p\u003e","function_template":"function y = return_nans(x)\r\n  \r\nend","test_suite":"%%\r\nx = 0./[6 4 0 3 -9];\r\ny_correct = [0   0   1   0   0];\r\nassert(isequal(return_nans(x),y_correct))\r\n\r\n%%\r\nx = [1 1 NaN NaN];\r\ny_correct = [0 0 1 1];\r\nassert(isequal(return_nans(x),y_correct))\r\n\r\n%%\r\nx =[1 1 NaN NaN; 5,2,3,NaN];\r\ny_correct = [0 0 1 1; 0 0 0 1];\r\nassert(isequal(return_nans(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-04-17T05:48:44.000Z","updated_at":"2026-03-09T20:40:54.000Z","published_at":"2018-04-17T05:48: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\",\"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\u003eReturn 1s wherever there is a NaN in the input 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":44687,"title":"basic matrix operations: rotate and find sum of diagonal elements of the resultant matrix","description":"For given input matrix a, rotate it by 90 degrees and find the sum of the diagonals.\r\n\r\nExample:\r\nInput:\r\n\r\n  a =\r\n\r\n     1     2     3     4\r\n     5     6     7     8\r\n     8    10    12    -2\r\n    -1    -3    -5    -7\r\n\r\nOutput is: \r\n\r\n  20","description_html":"\u003cp\u003eFor given input matrix a, rotate it by 90 degrees and find the sum of the diagonals.\u003c/p\u003e\u003cp\u003eExample:\r\nInput:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea =\r\n\u003c/pre\u003e\u003cpre\u003e     1     2     3     4\r\n     5     6     7     8\r\n     8    10    12    -2\r\n    -1    -3    -5    -7\u003c/pre\u003e\u003cp\u003eOutput is:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e20\r\n\u003c/pre\u003e","function_template":"function ans = matrix_manipulation(x)\r\n  \r\nend","test_suite":"%%\r\nx = [1 2 3 4; 5 6 7 8;8 10, 12, -2;-1 -3 -5,-7];\r\ny_correct = 20;\r\nassert(isequal(matrix_manipulation(x),y_correct))\r\n\r\n%%\r\nx = ones(5).*3\r\ny_correct = 15;\r\nassert(isequal(matrix_manipulation(x),y_correct))\r\n\r\n%%\r\na=[3,2,5]\r\nx = [a;a;a];\r\ny_correct = 10;\r\nassert(isequal(matrix_manipulation(x),y_correct))\r\n\r\n%%\r\nx = [-5,25,-10;8,-18,10;-2,7,-1]\r\ny_correct = -30;\r\nassert(isequal(matrix_manipulation(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":62,"test_suite_updated_at":"2018-06-13T08:54:27.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-06-13T08:49:50.000Z","updated_at":"2026-03-02T08:56:19.000Z","published_at":"2018-06-13T08:54:27.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 given input matrix a, rotate it by 90 degrees and find the sum of the diagonals.\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: Input:\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[a =\\n\\n     1     2     3     4\\n     5     6     7     8\\n     8    10    12    -2\\n    -1    -3    -5    -7]]\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\u003eOutput 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[20]]\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":44740,"title":"New Matrix with vector addition on diagonal","description":"consider 2 vectors \r\n\r\n  x=[1 2 3]\r\n  y=[4 5 6]\r\n\r\nthen generate a new Matrix, where Addition of x \u0026 y will be diagonal Elements of the new Matrix. i.e. new Matrix will have x+y=[5 7 9] as diagonal Elements\r\n\r\n  Output =[5     6     7\r\n           6     7     8\r\n           7     8     9]","description_html":"\u003cp\u003econsider 2 vectors\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3]\r\ny=[4 5 6]\r\n\u003c/pre\u003e\u003cp\u003ethen generate a new Matrix, where Addition of x \u0026 y will be diagonal Elements of the new Matrix. i.e. new Matrix will have x+y=[5 7 9] as diagonal Elements\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eOutput =[5     6     7\r\n         6     7     8\r\n         7     8     9]\r\n\u003c/pre\u003e","function_template":"function z = addmat(x,y)\r\n  z = x+y;\r\nend","test_suite":"%%\r\nx=[1 2 3];\r\ny=[4 5 6];\r\nz_correct = [5 6 7;6 7 8;7 8 9]\r\nassert(isequal(addmat(x,y),z_correct))\r\n\r\n%%\r\nx=[10 20 30 40];\r\ny=[-10 -20 -30 -40];\r\nz_correct = [0 10 20 30;-10 0 10 20;-20 -10 0 10;-30 -20 -10 0]\r\nassert(isequal(addmat(x,y),z_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":136465,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":47,"test_suite_updated_at":"2018-10-02T13:28:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-10-02T13:24:35.000Z","updated_at":"2026-02-27T14:16:57.000Z","published_at":"2018-10-02T13:24:35.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\u003econsider 2 vectors\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=[1 2 3]\\ny=[4 5 6]]]\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\u003ethen generate a new Matrix, where Addition of x \u0026amp; y will be diagonal Elements of the new Matrix. i.e. new Matrix will have x+y=[5 7 9] as diagonal Elements\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[Output =[5     6     7\\n         6     7     8\\n         7     8     9]]]\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":1926,"title":"Unit Matrix","description":"Given n, you should return an n-by-n unit matrix.\r\nExample:\r\nIf input is n=2 then\r\n A = [ 1 0 \r\n       0 1 ]\r\nIf input is n=4 then\r\n A = [ 1 0 0 0\r\n       0 1 0 0\r\n       0 0 1 0 \r\n       0 0 0 1 ]","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: 254.6px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 127.3px; transform-origin: 407px 127.3px; vertical-align: baseline; \"\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: 152.5px 8px; transform-origin: 152.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven n, you should return an n-by-n unit 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: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\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: 58px 8px; transform-origin: 58px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf input is n=2 then\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; 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 20.4333px; transform-origin: 404px 20.4333px; 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: 44px 8.5px; tab-size: 4; transform-origin: 44px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = [ 1 0 \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: 48px 8.5px; tab-size: 4; transform-origin: 48px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 1 ]\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: 58px 8px; transform-origin: 58px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf input is n=4 then\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 404px 40.8667px; 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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = [ 1 0 0 0\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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 1 0 0\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: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 1 0 \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: 64px 8.5px; tab-size: 4; transform-origin: 64px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 1 ]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;\r\ny_correct = [1 0;0 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = [1 0 0;0 1 0; 0 0 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":18257,"edited_by":223089,"edited_at":"2022-10-31T04:49:45.000Z","deleted_by":null,"deleted_at":null,"solvers_count":512,"test_suite_updated_at":"2022-10-31T04:49:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-10-09T18:48:08.000Z","updated_at":"2026-02-09T16:23:54.000Z","published_at":"2013-10-09T18:48:08.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eGiven n, you should return an n-by-n unit 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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf input is n=2 then\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[ A = [ 1 0 \\n       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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf input is n=4 then\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[ A = [ 1 0 0 0\\n       0 1 0 0\\n       0 0 1 0 \\n       0 0 0 1 ]]]\u003e\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":46105,"title":"Find sum of numbers on the cornice of a matrix.","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; vertical-align: baseline; perspective-origin: 407px 85.5px; transform-origin: 407px 85.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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003eGiven a matrix of random integers, calculate the sum of all the integers in the cornice of the matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003eFor example if MTX = [ \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e1 3 5 6;\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003e                                     \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e4\u003c/span\u003e\u003c/span\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=\"\"\u003e 7 9 \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e2;\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003e                                     \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e5\u003c/span\u003e\u003c/span\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=\"\"\u003e 6 1 \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e3;\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003e                                    \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e 7 9 2 1\u003c/span\u003e\u003c/span\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=\"\"\u003e]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003eoutput  = 1 + 3 + 5 + 6 + 4 + 2 + 5 + 3 + 7 + 9 + 2 + 1 = 48\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = sumCornice(MTX)\r\n  y = MTX;\r\nend","test_suite":"%% Test 1\r\nMTX = [ 1 3 5 6;\r\n        4 7 9 2;\r\n        5 6 1 3;\r\n        7 9 2 1];\r\ny_correct = 48;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 2\r\nMTX = [ 7     1     7     4     5\r\n     4     3     3     7     6\r\n     6     1     9     8     7\r\n     2     1     1     2     7\r\n     7     8     4     5     3];\r\ny_correct = 83;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 3\r\nMTX = [ 7     2\r\n     6     2];\r\ny_correct = 17;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 4\r\nMTX = [ 5     7     3     5     7     2     5     1\r\n     9     9     8     4     4     6     2     3\r\n     4     9     3     8     6     5     6     9\r\n     6     5     9     6     1     1     3     2\r\n     3     2     4     5     1     4     6     8\r\n     7     2     2     9     5     2     7     5\r\n     3     3     3     3     8     8     7     9\r\n     5     8     6     7     9     3     5     1];\r\ny_correct = 147;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 5\r\nMTX = [ 4     8     9     6     5     3\r\n     1     1     2     5     4     4\r\n     9     4     3     2     1     1\r\n     1     3     2     8     3     9\r\n     7     8     2     6     2     9\r\n     8     4     8     4     2     5];\r\ny_correct = 107;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":522328,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-08-05T18:20:14.000Z","updated_at":"2026-02-18T21:40:33.000Z","published_at":"2020-08-05T18:20:14.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\u003eGiven a matrix of random integers, calculate the sum of all the integers in the cornice 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 if MTX = [ \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1 3 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\u003e                                     \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e4\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 7 9 \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2;\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\u003e                                     \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 6 1 \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e3;\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\u003e                                    \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e 7 9 2 1\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput  = 1 + 3 + 5 + 6 + 4 + 2 + 5 + 3 + 7 + 9 + 2 + 1 = 48\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":44447,"title":"Eye Squared","description":"For a positive integer |n| create the identity matrix with |n| elements.\r\n\r\nIn case it is not possible to produce an identity matrix with exactly |n| elements, return an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n = 9\r\n  Output: I = [1 0 0\r\n               0 1 0\r\n               0 0 1]\r\n\r\n  Input:  n = 8\r\n  Output: I = []","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e create the identity matrix with \u003ctt\u003en\u003c/tt\u003e elements.\u003c/p\u003e\u003cp\u003eIn case it is not possible to produce an identity matrix with exactly \u003ctt\u003en\u003c/tt\u003e elements, return an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 9\r\nOutput: I = [1 0 0\r\n             0 1 0\r\n             0 0 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 8\r\nOutput: I = []\r\n\u003c/pre\u003e","function_template":"function I = eyeSquared(n)\r\n    I = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('eyeSquared.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 1;\r\nI_correct = 1;\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4;\r\nI_correct = [1 0; 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 9;\r\nI_correct = [1 0 0; 0 1 0; 0 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = -9;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 10;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4.1;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":234,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-11T00:36:01.000Z","updated_at":"2026-03-11T16:59:00.000Z","published_at":"2017-12-11T00:36:01.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 a positive integer\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e create the identity matrix 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements.\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 case it is not possible to produce an identity matrix with exactly\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements, return an empty 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\u003eExamples:\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[Input:  n = 9\\nOutput: I = [1 0 0\\n             0 1 0\\n             0 0 1]\\n\\nInput:  n = 8\\nOutput: I = []]]\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":1171,"title":"matrix of natural number","description":"Given a number n, create an n-by-n matrix in which the integers from 1 to n^2 resides seially as shown in the examples below.\r\n\r\nExamples:\r\n\r\n Input  n = 3\r\n Output a = [ 1 2 3\r\n              4 5 6\r\n              7 8 9 ]\r\n Input  n = 4\r\n Output a = [ 1     2     3     4\r\n              5     6     7     8\r\n              9    10    11    12\r\n              13   14    15    16]\r\n","description_html":"\u003cp\u003eGiven a number n, create an n-by-n matrix in which the integers from 1 to n^2 resides seially as shown in the examples below.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e Input  n = 3\r\n Output a = [ 1 2 3\r\n              4 5 6\r\n              7 8 9 ]\r\n Input  n = 4\r\n Output a = [ 1     2     3     4\r\n              5     6     7     8\r\n              9    10    11    12\r\n              13   14    15    16]\u003c/pre\u003e","function_template":"function y = nat_matrix(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(nat_matrix(x),y_correct))\r\n\r\n%%\r\n \r\nx = 5;\r\na = [  1 2 3 4 5; \r\n       6 7 8 9 10; \r\n      11 12 13 14 15; \r\n      16 17 18 19 20; \r\n      21 22 23 24 25];\r\nassert(isequal(a,nat_matrix(x)));\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":8433,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":295,"test_suite_updated_at":"2013-01-04T15:20:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-04T15:14:29.000Z","updated_at":"2026-02-18T09:23:26.000Z","published_at":"2013-01-04T15:15:20.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 number n, create an n-by-n matrix in which the integers from 1 to n^2 resides seially as shown in the examples below.\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\u003eExamples:\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[ Input  n = 3\\n Output a = [ 1 2 3\\n              4 5 6\\n              7 8 9 ]\\n Input  n = 4\\n Output a = [ 1     2     3     4\\n              5     6     7     8\\n              9    10    11    12\\n              13   14    15    16]]]\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":61296,"title":"Double the 2x2 Matrix","description":"In this challenge, you are given a predefined 2x2 matrix called x. Your task is to multiply every element in this matrix by 2 and return the result as y.\r\nExample:\r\nIf the input is:\r\n\r\nThe output should be:\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"baseline-shift: 0px; block-size: 267.4px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 469px 133.7px; transform-origin: 469px 133.7px; \"\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 21px; text-align: left; transform-origin: 445px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 139.267px 8px; transform-origin: 139.267px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn this challenge, you are given a predefined \u003c/span\u003e\u003c/span\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: 11.675px 8px; transform-origin: 11.675px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e2x2\u003c/span\u003e\u003c/span\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: 43.175px 8px; transform-origin: 43.175px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e matrix called \u003c/span\u003e\u003c/span\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: 3.89167px 8px; transform-origin: 3.89167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ex\u003c/span\u003e\u003c/span\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: 171.65px 8px; transform-origin: 171.65px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Your task is to multiply every element in this matrix by \u003c/span\u003e\u003c/span\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: 3.89167px 8px; transform-origin: 3.89167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e2\u003c/span\u003e\u003c/span\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: 66.5083px 8px; transform-origin: 66.5083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and return the result as \u003c/span\u003e\u003c/span\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: 3.89167px 8px; transform-origin: 3.89167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ey\u003c/span\u003e\u003c/span\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: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 31.1167px 8px; transform-origin: 31.1167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 41.6083px 8px; transform-origin: 41.6083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf the input is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 58.7px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 29.35px; text-align: left; transform-origin: 445px 29.35px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cimg class=\"imageNode\" style=\"vertical-align: baseline\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIM0lEQVRoQ+WbBYwsRRRF+bhbcF0suBM88IGQ4B7cJcHdLRCcj7sHgrsE1+DuHmxxd3fuSbp+enqrul71zPYs0y+52dnpku7bVa+ezbBRqsnY6nancKVwbrUhutprK82+q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RXlY+OipkLAlMS9eE9iKTvr0gUpKhNOTU3Sw5GINzHx5QU2w1VjhjwlYA2VlY9w/SRQOwKDESKMjWWYOA/xJyuJ9gj3EakQwKp3i58cYz2TfBxVr2Q22eQ1Xrl+weATONo3ep4U0bBUmJnmK/eMTjmZcLyxw3CicdYTyJmq82DboxrrMDnePffrASme3xOw0Cn4oQiTCUfpbAgtp3AClUycI+JGcqEVx9a0YkccJLHOWOJEC4lEo1aCO8IzX7ldEaAgc8KIo7kOXcRihz3w/gnNVn5y6vl/jtNyPlTSy7jjfxMqp7/AJDjoOPkc+dSBEGDi+KTF3h0G7ZFj7O9KK7dFX/H6qKPx8iaAjJktUrKQxEDoNS5stylbtFaGUDGOWF00ZQlRSSGMwfDmUPs5snb+uiz5IxQa4XNSqUBnkfksVHSqVNAZkeeMirShgOP5fhWe/W+DwwmU0SxXSUPr4lGSd8zaZedIh0pDCPRcgTXr5VUjjmTkRse6J6nYjItsu71trAHQzuYBk1+4/GZ2TRedh2dQAAAAASUVORK5CYII=\" data-image-state=\"image-loaded\"\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 67.6833px 8px; transform-origin: 67.6833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe output should be:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 58.7px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 29.35px; text-align: left; transform-origin: 445px 29.35px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cimg class=\"imageNode\" style=\"vertical-align: baseline\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIr0lEQVRoQ+XbB6xkVRkH8EXFihJ710UhCthj7GUVBVTElijFgr2Lisau2BFEwQ72rghiwQYC1qix94oulmCPvbf/L7mHzLvvlnNn35vFnS/5583cOfW753z9bbdhPjp/un04eHtwzHxDbNVe983sdwjuFfx16kq2m9oh7c8TnBB8LnheR/9L5tlVgl8GPw7+Pccca9llhwz2gOCo1qBPz/dbNsz725QJ52Ha6zLBJYJ9WxNdIN9fExww8/wX+eytfmjKota47Vsz3m2CS3eMe3qe/SB44JQ5pzLtMRn8icEuwR9aE70z378evDC4YHBg8OLg3MF+gd8XTZsyIcY49V1Mu3yefztwTd9bu7gpTLtZBv1EcNfgPa0JbpLvJwf3bzHnyfn+3GbRV8jff9YubA3aOfmfDK7XzH+ZnjHvkefHBjcIvlszby3TCP5vBt8P9u4Y+OF59rLm+WXz9+fN5yvl75nNZ0z/dM2i1qjNqzLOp4I3Br8Ouk5ameq0fLhww7j/js1fy7TDM9DBwW7BGR2D3iLPPhr8NLh68I+mDWYX7XT7fF6UbLtL5npIsFfwr4ZpfSfNUncPiBYv/5VrwTSnxQkz2KPHBmz9ft18/1Kz8CvmbzmBE4eZ1HzHtP5GcKPgZwHtPXbSTHB8QJva76AZUnPS2GG0y87BDyctf8OGo9P+UcGLgkMm9p23Oe3+5eClzQC1TCOXiQ/rtN5eGmMa7fKj4JSAMTiFCOAvBJ8Jbh38fUrnOds6KS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7/9XIucoNsbwpJc/D9MwiSmh+pldtDX++XVLXxSXj2zm2k3+H9T/AXW0r0VQewQcAAAAAElFTkSuQmCC\" data-image-state=\"image-loaded\"\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x; % Replace this with your code\r\nend\r\n","test_suite":"%% Test 1: Simple 2x2 Matrix\r\nx1 = [1 2; 3 4];\r\ny_correct1 = [2 4; 6 8];\r\nassert(isequal(your_fcn_name(x1), y_correct1))\r\n\r\n%% Test 2: Zero and Negatives\r\nx2 = [0 -5; 10 -1];\r\ny_correct2 = [0 -10; 20 -2];\r\nassert(isequal(your_fcn_name(x2), y_correct2))\r\n\r\n%% Test 3: Decimals\r\nx3 = [0.5 1.5; 2.5 3.5];\r\ny_correct3 = [1 3; 5 7];\r\nassert(isequal(your_fcn_name(x3), y_correct3))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":5088017,"edited_by":5088017,"edited_at":"2026-03-29T19:40:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2026-03-29T19:40:16.000Z","updated_at":"2026-04-03T16:34:17.000Z","published_at":"2026-03-29T19:40:20.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eIn this challenge, you are given a predefined \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2x2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix called \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Your task is to multiply every element in this matrix by \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and return the result as \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the input 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"53\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"77\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe output should be:\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:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"53\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"77\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.png\",\"relationshipId\":\"rId1\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image2.png\",\"relationshipId\":\"rId2\"}]},{\"partUri\":\"/media/image1.png\",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hDQ+MXOroPBJ2KKASU6gUyhtiCVpreOXtUOfclLn69BSSXtQ/bHN8Iyc/9kyZ8y3JNpBYoGl7YJyKQ9HuSZ1IK6+bTCJo5Kcah+3Ld19ppBGeB9dxkIJlfwHDwI3oXtojD1fHX6MQOpAKJRDyNpTHzFYwpakQqm4pbACUOzkcTkUqIQKCeYVyWEKGG8PNYqtNJYoRXlY+OipkLAlMS9eE9iKTvr0gUpKhNOTU3Sw5GINzHx5QU2w1VjhjwlYA2VlY9w/SRQOwKDESKMjWWYOA/xJyuJ9gj3EakQwKp3i58cYz2TfBxVr2Q22eQ1Xrl+weATONo3ep4U0bBUmJnmK/eMTjmZcLyxw3CicdYTyJmq82DboxrrMDnePffrASme3xOw0Cn4oQiTCUfpbAgtp3AClUycI+JGcqEVx9a0YkccJLHOWOJEC4lEo1aCO8IzX7ldEaAgc8KIo7kOXcRihz3w/gnNVn5y6vl/jtNyPlTSy7jjfxMqp7/AJDjoOPkc+dSBEGDi+KTF3h0G7ZFj7O9KK7dFX/H6qKPx8iaAjJktUrKQxEDoNS5stylbtFaGUDGOWF00ZQlRSSGMwfDmUPs5snb+uiz5IxQa4XNSqUBnkfksVHSqVNAZkeeMirShgOP5fhWe/W+DwwmU0SxXSUPr4lGSd8zaZedIh0pDCPRcgTXr5VUjjmTkRse6J6nYjItsu71trAHQzuYBk1+4/GZ2TRedh2dQAAAAASUVORK5CYII=\",\"relationship\":null},{\"partUri\":\"/media/image2.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIr0lEQVRoQ+XbB6xkVRkH8EXFihJ710UhCthj7GUVBVTElijFgr2Lisau2BFEwQ72rghiwQYC1qix94oulmCPvbf/L7mHzLvvlnNn35vFnS/5583cOfW753z9bbdhPjp/un04eHtwzHxDbNVe983sdwjuFfx16kq2m9oh7c8TnBB8LnheR/9L5tlVgl8GPw7+Pccca9llhwz2gOCo1qBPz/dbN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PSwt2TezZkTXhMrgVRDK4Nyp1UDExBsfrTAc2EzNT8X1aZffi1K8K/D3CQ0T+8ZjXrnaatx6tf0Y0xxRb8bGh7QiOcIgNlG7YpK5cc2KBdcwZqgN+alGTZBBDcosccBLaQSbrY+4XDQuBdhLY0zTUZaZMrhGwI/soo15qDqHxm1b/mwnGlitB9tvvejBGZj3whbrkkUYQkk9q2cBxTbtVQClXw3T2CqbA1ePgO0j9Q9sJI76r5pGjFsyAuOcttEa/S3gKMVFflqjSu1ZEiP8XnDzoC/5reBHlZFrPrjOGqaZ3NEntwjSvmpGuUKpP6exeAFOKXND3sGbXm9i9iilosmVVnnhKqBc2zcENGsXlapPnkT7v3FWta9lmhCLwmPyiXbqIwWA7DKLYH7oQ7guMkvvxBEnauZofuk3BS1DNSkiMIKOfM1RqmWagcg0JoXj76puK8RrYMwq+FGGMEpTmGYw8TVxJs5skVujk5yDG3Dz3AKVQQ5EFU1lmkFVEkooc9IXHZGt2lRlI3svQQYuYzXNwzSuisiuEIzK7/9XIucoNsbwpJc/D9MwiSmh+pldtDX++XVLXxSXj2zm2k3+H9T/AXW0r0VQewQcAAAAAElFTkSuQmCC\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44671,"title":"find number of times of occurrence of the most frequent number in a row vector","description":"In a given row vector, find the number of times a mode of a row vector has occurred\r\n\r\nexample: in [2 5 5 5 5 3], output is 4\r\n\r\n","description_html":"\u003cp\u003eIn a given row vector, find the number of times a mode of a row vector has occurred\u003c/p\u003e\u003cp\u003eexample: in [2 5 5 5 5 3], output is 4\u003c/p\u003e","function_template":"function y = num_mode(x)\r\n\r\nend","test_suite":"%%\r\nx =[2 3 3 3 5 3 3 5 5 5 5 5 5];\r\ny_correct = 7;\r\nassert(isequal(num_mode(x),y_correct))\r\n\r\n%%\r\nx =[8 8];\r\ny_correct = 2;\r\nassert(isequal(num_mode(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-31T15:30:12.000Z","updated_at":"2026-02-18T10:08:10.000Z","published_at":"2018-05-31T15:30:12.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\u003eIn a given row vector, find the number of times a mode of a row vector has occurred\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: in [2 5 5 5 5 3], output is 4\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":2350,"title":"What is Sum Of all elements of Matrix","description":"Given the matrix x, return the sum of all elements of matrix.\r\n\r\nExample:\r\n\r\n Input  x = [ 1 2 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is 24.\r\n\r\n Input  x = [ 1 NaN 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is NaN.","description_html":"\u003cp\u003eGiven the matrix x, return the sum of all elements of matrix.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  x = [ 1 2 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is 24.\u003c/pre\u003e\u003cpre\u003e Input  x = [ 1 NaN 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is NaN.\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1];\r\ny_correct = 1;\r\nassert(isequalwithequalnans(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 NaN 3 4 5 56];\r\ny_correct = NaN;\r\nassert(isequalwithequalnans(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":6,"created_by":25856,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":446,"test_suite_updated_at":"2014-09-09T14:35:09.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-06-06T07:35:17.000Z","updated_at":"2026-02-17T14:47:53.000Z","published_at":"2014-09-08T07:28:27.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 the matrix x, return the sum of all elements of 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\u003eExample:\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[ Input  x = [ 1 2 0 0 0\\n              0 6 9 3 3 ]\\n Output y is 24.\\n\\n Input  x = [ 1 NaN 0 0 0\\n              0 6 9 3 3 ]\\n Output y is NaN.]]\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":45173,"title":"Create the flag of Ramumbia","description":"The little known nation of Ramumbia has a very simple flag. It is made up of vertical stripes, Red, Green, Blue, that are equally spaced and with no gap between said stripes.\r\n\r\nThe artist that designed the flag has been very clear; \"If the flag is not divisible into three, equal, vertical segments, this flag shall not exist!\" However, bizarrely, the designer has given no guidance on the aspect ratio of the flag.\r\n\r\nYour task is to write a function which can reproduce said flag as a hypermatrix, viewable by the \"imshow\" function. The inputs to the function are the length, L and width, W of the flag, but remember, unless the width is divisible by three with no remainders, the flag will be blank (i.e. a hypermatrix of zeros of the appropriate size)","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; 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: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 103.5px; vertical-align: baseline; perspective-origin: 332px 103.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; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe little known nation of Ramumbia has a very simple flag. It is made up of vertical stripes, Red, Green, Blue, that are equally spaced and with no gap between said stripes.\u003c/span\u003e\u003c/span\u003e\u003c/div\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; transform-origin: 309px 31.5px; white-space: pre-wrap; perspective-origin: 309px 31.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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe artist that designed the flag has been very clear; \"If the flag is not divisible into three, equal, vertical segments, this flag shall not exist!\" However, bizarrely, the designer has given no guidance on the aspect ratio of the flag.\u003c/span\u003e\u003c/span\u003e\u003c/div\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; transform-origin: 309px 42px; white-space: pre-wrap; perspective-origin: 309px 42px; 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour task is to write a function which can reproduce said flag as a hypermatrix, viewable by the \"imshow\" function. The inputs to the function are the length, L and width, W of the flag, but remember, unless the width is divisible by three with no remainders, the flag will be blank (i.e. a hypermatrix of zeros of the appropriate size)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = RamumbiaFlag(L,W)\r\n  y = L*W;\r\nend","test_suite":"%%\r\nL = 1; W=3;\r\ny_correct(:,:,1) = [1,0,0]; \r\ny_correct(:,:,2) = [0,1,0]; \r\ny_correct(:,:,3) = [0,0,1]; \r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 3; W = 8;\r\ny_correct = zeros(L,W,3);\r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 10; W = 27;\r\ny_correct(:,:,1) = [ones(10,9),zeros(10,9),zeros(10,9)]; \r\ny_correct(:,:,2) = [zeros(10,9),ones(10,9),zeros(10,9)]; \r\ny_correct(:,:,3) = [zeros(10,9),zeros(10,9),ones(10,9)]; \r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 1000; W = 12119;\r\ny_correct = zeros(L,W,3);\r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 100; W = 999;\r\ny_correct(:,:,1) = [ones(100,333),zeros(100,333),zeros(100,333)]; \r\ny_correct(:,:,2) = [zeros(100,333),ones(100,333),zeros(100,333)]; \r\ny_correct(:,:,3) = [zeros(100,333),zeros(100,333),ones(100,333)]; \r\nassert(isequal(RamumbiaFlag(L,W),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":5,"created_by":157354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16,"test_suite_updated_at":"2020-09-28T19:13:22.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2019-10-11T22:19:48.000Z","updated_at":"2025-11-07T03:29:59.000Z","published_at":"2019-10-11T22:37:36.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\u003eThe little known nation of Ramumbia has a very simple flag. It is made up of vertical stripes, Red, Green, Blue, that are equally spaced and with no gap between said stripes.\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 artist that designed the flag has been very clear; \\\"If the flag is not divisible into three, equal, vertical segments, this flag shall not exist!\\\" However, bizarrely, the designer has given no guidance on the aspect ratio of the flag.\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\u003eYour task is to write a function which can reproduce said flag as a hypermatrix, viewable by the \\\"imshow\\\" function. The inputs to the function are the length, L and width, W of the flag, but remember, unless the width is divisible by three with no remainders, the flag will be blank (i.e. a hypermatrix of zeros of the appropriate size)\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":412,"title":"Back to basics 22 - Rotate a matrix","description":"Covering some basic topics I haven't seen elsewhere on Cody.\r\n\r\nRotate the input matrix 90 degrees counterclockwise (e.g. [1 2; 3 4] -\u003e [2 4; 1 3]\r\n","description_html":"\u003cp\u003eCovering some basic topics I haven't seen elsewhere on Cody.\u003c/p\u003e\u003cp\u003eRotate the input matrix 90 degrees counterclockwise (e.g. [1 2; 3 4] -\u003e [2 4; 1 3]\u003c/p\u003e","function_template":"function y = rotateBy90(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2; 3 4];\r\ny_correct = [2 4; 1 3];\r\nassert(isequal(rotateBy90(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3; 4 5 6; 7 8 9];\r\ny_correct = [ 3    6    9;    2    5    8;    1    4    7];\r\nassert(isequal(rotateBy90(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":4,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":937,"test_suite_updated_at":"2016-10-23T02:03:04.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-02-25T21:37:41.000Z","updated_at":"2026-03-16T18:52:05.000Z","published_at":"2012-02-25T21:41:25.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\u003eCovering some basic topics I haven't seen elsewhere on Cody.\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\u003eRotate the input matrix 90 degrees counterclockwise (e.g. [1 2; 3 4] -\u003e [2 4; 1 3]\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":44624,"title":"Return median of a matrix","description":"Compute median of a matrix of any dimension. Exclude the NaNs if any.","description_html":"\u003cp\u003eCompute median of a matrix of any dimension. Exclude the NaNs if any.\u003c/p\u003e","function_template":"function y = matrix_median(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [2,3,4;4,5,6];\r\ny_correct = 4;\r\nassert(isequal(matrix_median(x),y_correct))\r\n\r\n%%\r\nx = int8(1:4);\r\ny_correct = 3;\r\nassert(isequal(matrix_median(x),y_correct))\r\n\r\n%%\r\nx = [2 6 8 10 NaN 14 NaN 18 NaN];\r\ny_correct = 9;\r\nassert(isequal(matrix_median(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-04-21T04:30:24.000Z","updated_at":"2026-02-18T11:12:59.000Z","published_at":"2018-04-21T04:30:24.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\u003eCompute median of a matrix of any dimension. Exclude the NaNs if any.\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":45502,"title":"Basic Operation with the middle number of odd matrix","description":"# Take an odd matrix *like* 3-by-3\r\n# Access the *middle element* of the matrix i.e in case of 3-by-3 matrix the index of the particular element is second row, second column.\r\n# Now, *sum* the elements in its column to it and then *subtract* the elements in its row to it.\r\n# What's the matrix with updated element.","description_html":"\u003col\u003e\u003cli\u003eTake an odd matrix \u003cb\u003elike\u003c/b\u003e 3-by-3\u003c/li\u003e\u003cli\u003eAccess the \u003cb\u003emiddle element\u003c/b\u003e of the matrix i.e in case of 3-by-3 matrix the index of the particular element is second row, second column.\u003c/li\u003e\u003cli\u003eNow, \u003cb\u003esum\u003c/b\u003e the elements in its column to it and then \u003cb\u003esubtract\u003c/b\u003e the elements in its row to it.\u003c/li\u003e\u003cli\u003eWhat's the matrix with updated element.\u003c/li\u003e\u003c/ol\u003e","function_template":"function y = your_fcn_name(A)\r\n% A is square matrix with odd rows and column or a row vector or a column vector\r\n%Write your code here\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 10; 7 8 9];\r\ny_correct = [1     2     3; 4     1    10; 7     8     9];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny_correct = [1     2    -9     4     5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1; 2; 3; 4; 5];\r\ny_correct = [1; 2; 15; 4; 5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":26467,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":"2020-05-09T17:11:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-07T19:17:59.000Z","updated_at":"2025-07-06T19:41:21.000Z","published_at":"2020-05-08T18:14: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\",\"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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTake an odd matrix\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\u003elike\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 3-by-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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAccess the\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\u003emiddle element\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the matrix i.e in case of 3-by-3 matrix the index of the particular element is second row, second column.\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\u003eNow,\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\u003esum\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the elements in its column to it and then\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\u003esubtract\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the elements in its row to it.\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\u003eWhat's the matrix with updated element.\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":1671,"title":"Generate the Matrix!","description":"Given n, generate the following matrix:\r\n\r\n  a = [ n  n-1 n-2 ... 2 1;\r\n       n-1 n-1 n-2 ... 2 1;\r\n       n-2 n-2 n-2 ... 2 1;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        2   2   2  ... 2 1;\r\n        1   1   1  ... 1 1]\r\n\r\nGood luck!","description_html":"\u003cp\u003eGiven n, generate the following matrix:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea = [ n  n-1 n-2 ... 2 1;\r\n     n-1 n-1 n-2 ... 2 1;\r\n     n-2 n-2 n-2 ... 2 1;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      2   2   2  ... 2 1;\r\n      1   1   1  ... 1 1]\r\n\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = mat_fun(n)\r\n  y = ones(n);\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 2;\r\ny_correct = [2 1; 1 1];\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = [3 2 1; 2 2 1; 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 4;\r\ny_correct = [4 3 2 1; 3 3 2 1; 2 2 2 1; 1 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":14930,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-21T17:16:38.000Z","updated_at":"2026-03-11T08:53:15.000Z","published_at":"2013-06-21T17:23:38.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, generate the following matrix:\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[a = [ n  n-1 n-2 ... 2 1;\\n     n-1 n-1 n-2 ... 2 1;\\n     n-2 n-2 n-2 ... 2 1;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      2   2   2  ... 2 1;\\n      1   1   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\u003eGood 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":44842,"title":"Double the next!","description":"Given two numbers, m and n, find a matrix [m,n] where each element value is twice the value of the previous element. Starting from the position (1,1) with value equal to 1, until the position (m,n), following the direction from left to right and from top to bottom.\r\nFor example, for m=2 and n=3, you should get:\r\ny = [1 2 4; 8 16 32].","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 123.438px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 332px 61.7188px; transform-origin: 332px 61.7188px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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: 309px 31.5px; text-align: left; transform-origin: 309px 31.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two numbers, m and n, find a matrix \u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; \"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003em,n\u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; \"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e where each element value is twice the value of the previous element. Starting from the position (1,1) with value equal to 1, until the position (m,n), following the direction from left to right and from top to bottom.\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: 309px 10.5px; text-align: left; transform-origin: 309px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, for m=2 and n=3, you should get:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4375px; 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: 329px 10.2188px; transform-origin: 329px 10.2188px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); 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; text-wrap: 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ey = [1 2 4; 8 16 32].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(m,n)\r\n  y = [];\r\nend","test_suite":"%%\r\nm = 3;\r\nn = 2; \r\ny_correct = [1 2; 4 8; 16 32];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 1;\r\nn = 1; \r\ny_correct = [1];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 1;\r\nn = 5; \r\ny_correct = [1 2 4 8 16];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 3;\r\nn = 1; \r\ny_correct = [1; 2; 4];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 4;\r\nn = 2; \r\ny_correct = [1 2; 4 8; 16 32; 64 128];\r\nassert(isequal(your_fcn_name(m,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":274816,"edited_by":274816,"edited_at":"2024-07-03T13:09:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":54,"test_suite_updated_at":"2019-03-23T22:36:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-01-29T11:50:39.000Z","updated_at":"2026-03-04T14:52:41.000Z","published_at":"2019-01-29T11:50:39.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\u003eGiven two numbers, m and n, find a matrix [m,n] where each element value is twice the value of the previous element. Starting from the position (1,1) with value equal to 1, until the position (m,n), following the direction from left to right and from top to bottom.\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 m=2 and n=3, you should get:\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 = [1 2 4; 8 16 32].]]\u003e\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":44973,"title":"Create a \"+\" flag","description":"Given two odd numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0. \r\n\r\nFor example, [m, n] = [3, 3] would return\r\n\r\n  [0, 1, 0; \r\n   1, 1, 1; \r\n   0, 1, 0]\r\n\r\nIf either m or n is even, there is no row of ones (for m) or no column of ones (for n). So [m, n] = [4, 3] would return\r\n\r\n  [0, 1, 0; \r\n   0, 1, 0; \r\n   0, 1, 0; \r\n   0, 1, 0]\r\n\r\n[m, n] =[4, 4] would return \r\n\r\n  [0, 0, 0, 0; \r\n   0, 0, 0, 0;\r\n   0, 0, 0, 0; \r\n   0, 0, 0, 0]","description_html":"\u003cp\u003eGiven two odd numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\u003c/p\u003e\u003cp\u003eFor example, [m, n] = [3, 3] would return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[0, 1, 0; \r\n 1, 1, 1; \r\n 0, 1, 0]\r\n\u003c/pre\u003e\u003cp\u003eIf either m or n is even, there is no row of ones (for m) or no column of ones (for n). So [m, n] = [4, 3] would return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[0, 1, 0; \r\n 0, 1, 0; \r\n 0, 1, 0; \r\n 0, 1, 0]\r\n\u003c/pre\u003e\u003cp\u003e[m, n] =[4, 4] would return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[0, 0, 0, 0; \r\n 0, 0, 0, 0;\r\n 0, 0, 0, 0; \r\n 0, 0, 0, 0]\r\n\u003c/pre\u003e","function_template":"function y = crossFlag(m, n)\r\n  y = zeros(m,n);\r\nend","test_suite":"%%\r\nm = 3; n = 3;\r\ny_correct = [0, 1, 0; 1, 1, 1; 0, 1, 0];\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 5; n = 3;\r\ny_correct = [0, 1, 0; 0, 1, 0; 1, 1, 1; 0, 1, 0; 0, 1, 0];\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 16; n = 8;\r\ny_correct = zeros(16,8);\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 7; n = 280;\r\ny_correct = [zeros(3,280); ones(1,280); zeros(3,280)];\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 1; n = 1;\r\ny_correct = 1;\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 7; n = 13;\r\ny_correct =[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0];\r\nassert(isequal(crossFlag(m, n),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":157354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":"2019-10-09T18:25:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-03T11:15:19.000Z","updated_at":"2026-03-24T11:58:02.000Z","published_at":"2019-10-03T11:15: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\u003eGiven two odd numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\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, [m, n] = [3, 3] would return\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, 0; \\n 1, 1, 1; \\n 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\u003eIf either m or n is even, there is no row of ones (for m) or no column of ones (for n). So [m, n] = [4, 3] would return\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, 0; \\n 0, 1, 0; \\n 0, 1, 0; \\n 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\u003e[m, n] =[4, 4] would return\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, 0, 0, 0; \\n 0, 0, 0, 0;\\n 0, 0, 0, 0; \\n 0, 0, 0, 0]]]\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":44635,"title":"Repetition of matrices","description":"*A is a bold matrix: [1 2 3; 4 5 6;7 8 9]*\r\n\r\nGiven an integer 'n' , a matrix B exists such that has n copies of A in the row and column dimensions\r\n\r\nexample:\r\nfor n=2; B= [A A; A A]\r\n\r\nFor such a matrix B return the sum of all elements multiplied by the size of B i.e. \r\n\r\n  C=sum (all elements of B) * size(B)\r\n\r\n* _Kindly note you will have to make the matrix A yourself_ *","description_html":"\u003cp\u003e\u003cb\u003eA is a bold matrix: [1 2 3; 4 5 6;7 8 9]\u003c/b\u003e\u003c/p\u003e\u003cp\u003eGiven an integer 'n' , a matrix B exists such that has n copies of A in the row and column dimensions\u003c/p\u003e\u003cp\u003eexample:\r\nfor n=2; B= [A A; A A]\u003c/p\u003e\u003cp\u003eFor such a matrix B return the sum of all elements multiplied by the size of B i.e.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eC=sum (all elements of B) * size(B)\r\n\u003c/pre\u003e\u003cul\u003e\u003cli\u003e\u003ci\u003eKindly note you will have to make the matrix A yourself\u003c/i\u003e *\u003c/li\u003e\u003c/ul\u003e","function_template":"function C = matrix_rep(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nn = 2;\r\nC_correct = [1080,1080];\r\nassert(isequal(matrix_rep(n),C_correct))\r\n\r\n%%\r\nn = 5;\r\nC_correct = [16875,16875];\r\nassert(isequal(matrix_rep(n),C_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":"2018-05-09T11:43:47.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T11:42:39.000Z","updated_at":"2026-03-05T11:04:40.000Z","published_at":"2018-05-09T11:42: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA is a bold matrix: [1 2 3; 4 5 6;7 8 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\u003eGiven an integer 'n' , a matrix B exists such that has n copies of A in the row and column dimensions\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 n=2; B= [A A; A A]\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 such a matrix B return the sum of all elements multiplied by the size of B i.e.\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[C=sum (all elements of B) * size(B)]]\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eKindly note you will have to make the matrix A yourself\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\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":42456,"title":"Create an array (n,n) where only diagonal elements are '1' and others are '0'","description":"Create an array (n,n) where only diagonal elements are '1' and others are '0'\r\n\r\nEX: n = 3;\r\nthen Resultant array would be [ 1 0 1\r\n\r\n                                0 1 0\r\n\r\n                                1 0 1 ]                                 ","description_html":"\u003cp\u003eCreate an array (n,n) where only diagonal elements are '1' and others are '0'\u003c/p\u003e\u003cp\u003eEX: n = 3;\r\nthen Resultant array would be [ 1 0 1\u003c/p\u003e\u003cpre\u003e                                0 1 0\u003c/pre\u003e\u003cpre\u003e                                1 0 1 ]                                 \u003c/pre\u003e","function_template":"function y = getArrayWithDiagOnes(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(getArrayWithDiagOnes(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = [1,1;1,1];\r\nassert(isequal(getArrayWithDiagOnes(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [1 0 0 0 1;0 1 0 1 0;0 0 1 0 0;0 1 0 1 0;1 0 0 0 1];\r\nassert(isequal(getArrayWithDiagOnes(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46593,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-07-09T06:27:11.000Z","updated_at":"2026-02-18T15:40:46.000Z","published_at":"2015-07-09T06:29:00.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\u003eCreate an array (n,n) where only diagonal elements are '1' and others are '0'\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\u003eEX: n = 3; then Resultant array would be [ 1 0 1\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 0\\n\\n                                1 0 1 ]]]\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":44665,"title":"Percentage of zeros in a matrix of only 1s and 0s","description":"Write a function called _zero_stat_ that takes a matrix as an input that only has 0 and 1 elements. The function needs to compute and return the percentage of 0 elements in the matrix. For example, if there are 10 zeros and 15 ones in a 5-by-5 matrix that is provided as an input to zero_stat, it would return 40 because 40% of the elements are zero.\r\n*Please return the answer rounded to the nearest integer*","description_html":"\u003cp\u003eWrite a function called \u003ci\u003ezero_stat\u003c/i\u003e that takes a matrix as an input that only has 0 and 1 elements. The function needs to compute and return the percentage of 0 elements in the matrix. For example, if there are 10 zeros and 15 ones in a 5-by-5 matrix that is provided as an input to zero_stat, it would return 40 because 40% of the elements are zero. \u003cb\u003ePlease return the answer rounded to the nearest integer\u003c/b\u003e\u003c/p\u003e","function_template":"function pct_zero = zero_stat(inp_matrix)\r\nend","test_suite":"%%\r\ninp_matrix = [1,0,0,1,1;0,1,1,0,0;0,0,0,0,0;1,1,1,1,1;1,1,1,1,1];\r\npct_zero_corr = 40;\r\nassert(isequal(zero_stat(inp_matrix),pct_zero_corr))\r\n\r\n%%\r\ninp_matrix = diag([1,0,1,1,1]);\r\npct_zero_corr = 84;\r\nassert(isequal(zero_stat(inp_matrix),pct_zero_corr))\r\n\r\n%%\r\ninp_matrix = [1,0,1,0,0,0,1]';\r\npct_zero_corr = 57;\r\nassert(isequal(zero_stat(inp_matrix),pct_zero_corr))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-29T15:29:49.000Z","updated_at":"2026-04-02T10:26:58.000Z","published_at":"2018-05-29T15:29:49.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\u003eWrite a function called\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\u003ezero_stat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that takes a matrix as an input that only has 0 and 1 elements. The function needs to compute and return the percentage of 0 elements in the matrix. For example, if there are 10 zeros and 15 ones in a 5-by-5 matrix that is provided as an input to zero_stat, it would return 40 because 40% of the elements are zero.\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\u003ePlease return the answer rounded to the nearest integer\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":42457,"title":"Get the array of sum for three consecutive numbers in an array","description":"Get the array of sum, for three consecutive numbers in an array.\r\n\r\nif Input 'x' does not have at-least 3 elements then 'y' should be zero. \r\n\r\nEX:- x = [1,2,3,4] then y = [6,9]\r\n\r\n   x = [4,9,2,6,1,7] then y = [15,17,9,14]\r\n  \r\n   x = 1 then y = 0;\r\n\r\n\r\n","description_html":"\u003cp\u003eGet the array of sum, for three consecutive numbers in an array.\u003c/p\u003e\u003cp\u003eif Input 'x' does not have at-least 3 elements then 'y' should be zero.\u003c/p\u003e\u003cp\u003eEX:- x = [1,2,3,4] then y = [6,9]\u003c/p\u003e\u003cpre\u003e   x = [4,9,2,6,1,7] then y = [15,17,9,14]\u003c/pre\u003e\u003cpre\u003e   x = 1 then y = 0;\u003c/pre\u003e","function_template":"function y = GetSumOf3Numbers(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [15,17];\r\ny_correct = 0;\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\nx = [1];\r\ny_correct = 0;\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\n\r\nx = [1,2,3];\r\ny_correct = 6;\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\n\r\nx = [4,9,2,6,1,7];\r\ny_correct = [15,17,9,14];\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46593,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-07-09T09:25:12.000Z","updated_at":"2025-08-30T13:37:09.000Z","published_at":"2015-07-09T09:25:12.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\u003eGet the array of sum, for three consecutive numbers in an array.\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\u003eif Input 'x' does not have at-least 3 elements then 'y' should be zero.\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\u003eEX:- x = [1,2,3,4] then y = [6,9]\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 = [4,9,2,6,1,7] then y = [15,17,9,14]\\n\\n   x = 1 then y = 0;]]\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":43122,"title":"Upper Matrix Mock","description":"Given a vector v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:\r\n\r\nm=[1 3 6 9 11;\r\n   0 1 3 6 9;\r\n   0 0 1 3 6;\r\n   0 0 0 1 3;\r\n   0 0 0 0 1]","description_html":"\u003cp\u003eGiven a vector v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:\u003c/p\u003e\u003cp\u003em=[1 3 6 9 11;\r\n   0 1 3 6 9;\r\n   0 0 1 3 6;\r\n   0 0 0 1 3;\r\n   0 0 0 0 1]\u003c/p\u003e","function_template":"function y = upMatMock(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 3 6 9 11];\r\ny_correct = [1 3 6 9 11;\r\n   0 1 3 6 9;\r\n   0 0 1 3 6;\r\n   0 0 0 1 3;\r\n   0 0 0 0 1]\r\nassert(isequal(upMatMock(x),y_correct))\r\n%%\r\nx = [7 8 9 11];\r\ny_correct = [7 8 9 11;\r\n   0 7 8 9;\r\n   0 0 7 8;\r\n   0 0 0 7]\r\nassert(isequal(upMatMock(x),y_correct))","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":13865,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":"2016-10-29T17:02:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-06T10:26:31.000Z","updated_at":"2026-03-16T10:56:25.000Z","published_at":"2016-10-06T10:25:53.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 vector v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:\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 3 6 9 11; 0 1 3 6 9; 0 0 1 3 6; 0 0 0 1 3; 0 0 0 0 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":44402,"title":"Horizontal matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 9  2  8  1\r\n      5  4  9  8\r\n      8  9  6  9\r\n  \r\n  y = 1  2  8  9  9  8  2  1\r\n      4  5  8  9  9  8  5  4\r\n      6  8  9  9  9  9  8  6","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 9  2  8  1\r\n    5  4  9  8\r\n    8  9  6  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 1  2  8  9  9  8  2  1\r\n    4  5  8  9  9  8  5  4\r\n    6  8  9  9  9  9  8  6\r\n\u003c/pre\u003e","function_template":"function y = backAndforth(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0 0];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = zeros(100);\r\nx(41,68) = 1;\r\ny_correct = zeros(100,200);\r\ny_correct(41,100:101) = [1,1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 2 3 4 4 3 2 1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x,fliplr(x)];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x,x];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1; 4; 3; 2];\r\ny_correct = [1 1; 4 4; 3 3; 2 2];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [9  2  8  1; 5  4  9  8; 8  9  6  9];\r\ny_correct = [1  2  8  9  9  8  2  1;\r\n             4  5  8  9  9  8  5  4;\r\n             6  8  9  9  9  9  8  6];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nr = [1:3:7,7:-3:1];\r\ny_correct = [r;r+1;r+2];\r\nassert(isequal(backAndforth(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":"2018-01-02T21:54:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-12T07:54:27.000Z","updated_at":"2026-03-29T20:13:01.000Z","published_at":"2017-11-12T07:59: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\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\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:\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 = 9  2  8  1\\n    5  4  9  8\\n    8  9  6  9\\n\\ny = 1  2  8  9  9  8  2  1\\n    4  5  8  9  9  8  5  4\\n    6  8  9  9  9  9  8  6]]\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":1812,"title":"Tridiagonal","description":"Return an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\r\n\r\nExample \r\n\r\n a=1\r\n b=2\r\n c=3\r\n n=5\r\n T =  [2     3     0     0     0;\r\n       1     2     3     0     0;\r\n       0     1     2     3     0;\r\n       0     0     1     2     3;\r\n       0     0     0     1     2]\r\n","description_html":"\u003cp\u003eReturn an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e a=1\r\n b=2\r\n c=3\r\n n=5\r\n T =  [2     3     0     0     0;\r\n       1     2     3     0     0;\r\n       0     1     2     3     0;\r\n       0     0     1     2     3;\r\n       0     0     0     1     2]\u003c/pre\u003e","function_template":"function T = tridiag(a, b, c, n)\r\n  \r\nend","test_suite":"%%\r\na = 1;\r\nb = 2;\r\nc = 3;\r\nn = 5;\r\ny_correct = [ 2     3     0     0     0;\r\n              1     2     3     0     0;\r\n              0     1     2     3     0;\r\n              0     0     1     2     3;\r\n              0     0     0     1     2];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 9;\r\nb = 5;\r\nc = -17;\r\nn = 3;\r\ny_correct = [ 5   -17     0 ;\r\n              9     5   -17 ;\r\n              0     9     5 ];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 4;\r\nb = -1;\r\nc = 8;\r\nn = 4;\r\ny_correct = [-1     8     0     0;\r\n              4    -1     8     0;\r\n              0     4    -1     8;\r\n              0     0     4    -1];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 11;\r\nb = 21;\r\nc = 30;\r\nn = 5;\r\ny_correct = [21    30     0     0     0;\r\n             11    21    30     0     0;\r\n              0    11    21    30     0;\r\n              0     0    11    21    30;\r\n              0     0     0    11    21];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":14639,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":173,"test_suite_updated_at":"2017-03-15T16:29:22.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-08-14T09:35:02.000Z","updated_at":"2026-02-27T15:40:54.000Z","published_at":"2013-08-14T09:35:02.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\u003eReturn an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in 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\u003eExample\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[ a=1\\n b=2\\n c=3\\n n=5\\n T =  [2     3     0     0     0;\\n       1     2     3     0     0;\\n       0     1     2     3     0;\\n       0     0     1     2     3;\\n       0     0     0     1     2]]]\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":44496,"title":"vector indexes for a matrix","description":"Matlab allows us to use several indexing styles making code simpler and easier to read than using loops. \r\n\r\nVectors can have vector subscripts\r\n\r\n  V = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n     2     4     6\r\n\r\nIn case of matrices, it allows us to use linear indexing.\r\n \r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n     2     4     6\r\n\r\n\r\nGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops. \r\n\r\nFor example (tl;dr)\r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\n  P = [1 1 2]; Q = [1 3 2];\r\n  Matrix_VectorIndexes(M,P,Q)\r\n  ans =\r\n     2     4     6\r\n\r\n","description_html":"\u003cp\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\u003c/p\u003e\u003cp\u003eVectors can have vector subscripts\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eV = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eIn case of matrices, it allows us to use linear indexing.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\u003c/p\u003e\u003cp\u003eFor example (tl;dr)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 1 2]; Q = [1 3 2];\r\nMatrix_VectorIndexes(M,P,Q)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e","function_template":"function y = Matrix_VectorIndexes(M,P,Q)\r\n  y = M(P,Q);  %M(P,Q) gives wrong answer because matlab reads it as linear indexing of matrices \r\n               % M(1,1) is not considered linear indexing, but M([1,1]),M([1],[1]) etc., is \r\nend","test_suite":"%%\r\nM = [1 2 3;\r\n     4 5 6;\r\n     7 8 9];\r\nP = [1 2 3]; Q= [1 2 3];\r\ny_correct = [1,5,9];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 3 2]; Q = [1 1 2];\r\ny_correct = [2,4,6];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = 1:3; Q = 3:-1:1;\r\ny_correct = [4,9,8];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = reshape(repmat((1:3)',[1,3]),[1,9]);\r\nQ = reshape(repmat(1:3,[3,1]),[1,9]);\r\ny_correct = M(:)';\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4 2;\r\n     7 9 6 1; \r\n     8 2 3 5];\r\nP = [2,1,3,2]; Q = 1:4;\r\ny_correct = [7,5,3,1];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":162999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2018-06-16T21:47:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-10T07:13:18.000Z","updated_at":"2026-04-02T13:18:07.000Z","published_at":"2018-01-10T07:33:32.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\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\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\u003eVectors can have vector subscripts\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[V = [2 3 4 5 6 7 8 9 10];\\nidx = [1 3 5];\\nV(idx)\\nans =\\n   2     4     6]]\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\u003eIn case of matrices, it allows us to use linear indexing.\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nidx = [1 3 5];\\nM(idx) \\nans =\\n   2     4     6]]\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\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\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 (tl;dr)\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nP = [1 1 2]; Q = [1 3 2];\\nMatrix_VectorIndexes(M,P,Q)\\nans =\\n   2     4     6]]\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":411,"title":"Back to basics 21 - Matrix replicating","description":"Covering some basic topics I haven't seen elsewhere on Cody.\r\n\r\nGiven an input matrix, generate an output matrix that consists of the input matrix replicated in a 2 by 2 pattern Examples:\r\n\r\n  [1] -\u003e [1 1\r\n          1 1]\r\n\r\n  [1 2       -\u003e [1 2 1 2\r\n   3 4]          3 4 3 4 \r\n                 1 2 1 2 \r\n                 3 4 3 4]","description_html":"\u003cp\u003eCovering some basic topics I haven't seen elsewhere on Cody.\u003c/p\u003e\u003cp\u003eGiven an input matrix, generate an output matrix that consists of the input matrix replicated in a 2 by 2 pattern Examples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[1] -\u003e [1 1\r\n        1 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e[1 2       -\u003e [1 2 1 2\r\n 3 4]          3 4 3 4 \r\n               1 2 1 2 \r\n               3 4 3 4]\r\n\u003c/pre\u003e","function_template":"function y = matrix_replication(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1];\r\ny_correct = [1 1;1 1];\r\nassert(isequal(matrix_replication(x),y_correct))\r\n\r\n%%\r\nx = [1 2;3 4];\r\ny_correct = [1 2 1 2; 3 4 3 4; 1 2 1 2; 3 4 3 4];\r\nassert(isequal(matrix_replication(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 2];\r\ny_correct = [1 2 1 2; 1 2 1 2];\r\nassert(isequal(matrix_replication(x),y_correct))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1798,"test_suite_updated_at":"2012-02-25T21:33:19.000Z","rescore_all_solutions":false,"group_id":19,"created_at":"2012-02-25T21:33:19.000Z","updated_at":"2026-03-28T23:57:05.000Z","published_at":"2012-02-25T21:33: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\u003eCovering some basic topics I haven't seen elsewhere on Cody.\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 an input matrix, generate an output matrix that consists of the input matrix replicated in a 2 by 2 pattern Examples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[1] -\u003e [1 1\\n        1 1]\\n\\n[1 2       -\u003e [1 2 1 2\\n 3 4]          3 4 3 4 \\n               1 2 1 2 \\n               3 4 3 4]]]\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":42646,"title":"Matrix FUN","description":"Given a Matrix M, find out the number of elements of matrix that are divisible by 3.\r\n\r\n  \r\n    M = [1 2 3;4 5 6;7 8 9];\r\n    out = 3\r\n\r\n    M = [32 12 15; 2 6 45];\r\n    out = 4\r\n ","description_html":"\u003cp\u003eGiven a Matrix M, find out the number of elements of matrix that are divisible by 3.\u003c/p\u003e\u003cpre\u003e    M = [1 2 3;4 5 6;7 8 9];\r\n    out = 3\u003c/pre\u003e\u003cpre\u003e    M = [32 12 15; 2 6 45];\r\n    out = 4\u003c/pre\u003e","function_template":"function y = mat_fun(m)\r\n  y = x; %think and solve\r\nend","test_suite":"%%\r\nx = 4;\r\ny_correct = 0;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [3 2 3 2 5 6 2 1 2];\r\ny_correct = 3;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [999 999 999 2 15 6];\r\ny_correct = 5;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = 3:3:999;\r\ny_correct = 333;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [1 2 3 4 5 6;6 5 4 3 2 1];\r\ny_correct = 4;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [7 8 11 13 14 17];\r\ny_correct = 0;\r\nassert(isequal(mat_fun(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":44015,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":165,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-03T05:59:11.000Z","updated_at":"2026-03-23T15:33:33.000Z","published_at":"2015-10-03T06:00:26.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 Matrix M, find out the number of elements of matrix that are divisible by 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[    M = [1 2 3;4 5 6;7 8 9];\\n    out = 3\\n\\n    M = [32 12 15; 2 6 45];\\n    out = 4]]\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":54440,"title":"Create an arrow matrix","description":"An arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \r\n                                        \r\n                                        \r\n\r\nWrite a function that takes the number of rows and columns (for N \u003e= 3) as an input, and returns the corresponding arrow matrix.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 305px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 152.5px; transform-origin: 407px 152.5px; vertical-align: baseline; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 164px; 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 82px; text-align: left; transform-origin: 384px 82px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003cimg class=\"imageNode\" width=\"199\" height=\"158\" style=\"vertical-align: baseline;width: 199px;height: 158px\" src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC05NDYgLTMzMCkiPjxwYXRoIGQ9Ik05NDguMzQ5IDMzMy4yMDQgMTM0NC42MyAzMzMuMjA0IDEzNDQuNjMgNjM3LjU1IDk0OC4zNDkgNjM3LjU1WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTEzNDQuNjMgMzMzLjIwNCAxNzQwLjkyIDMzMy4yMDQgMTc0MC45MiA2MzcuNTUgMTM0NC42MyA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzMuMjA0IDIxMzcuMiAzMzMuMjA0IDIxMzcuMiA2MzcuNTUgMTc0MC45MiA2MzcuNTVaIiBmaWxsPSIjRjh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E8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\" data-image-state=\"image-loaded\"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of rows and columns (for \u003c/span\u003e\u003c/span\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eN\u003c/span\u003e\u003c/span\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = arrow(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [1 0 1; 0 1 1; 1 1 1];\r\nassert(isequal(arrow(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = [1 0 0 0 0 1; 0 1 0 0 0 1; 0 0 1 0 0 1; 0 0 0 1 0 1; 0 0 0 0 1 1; 1 1 1 1 1 1];\r\nassert(isequal(arrow(x),y_correct))","published":true,"deleted":false,"likes_count":11,"comments_count":1,"created_by":571375,"edited_by":571375,"edited_at":"2022-10-03T14:11:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":560,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-05-03T17:40:18.000Z","updated_at":"2026-03-20T13:55:48.000Z","published_at":"2022-10-03T14:11:46.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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\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\u003e                                        \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"158\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"199\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes the number of rows and columns (for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.svg+xml\",\"relationshipId\":\"rId1\"}]},{\"partUri\":\"/media/image1.svg+xml\",\"contentType\":\"image/svg+xml\",\"content\":\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5z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OCIgeD0iMTE4OC44NSIgeT0iNjI4Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjYyOCI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIwIiB5PSI5NDYiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMzk2LjI4NSIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjExODguODUiIHk9Ijk0NiI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxNTg1LjE0IiB5PSI5NDYiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":43073,"title":"Check if a matrix is a palindrome in all directions","description":"Check if a matrix is a palindrome both vertically and horizontally.\r\n\r\nYou function will return *true* for |[1,2,1]| or |[2,7,2; 6,9,6; 2,7,2]| . But it should return *false* for |[1,2,3]| or |[2,7,2; 6,9,6; 3,5,3]| .","description_html":"\u003cp\u003eCheck if a matrix is a palindrome both vertically and horizontally.\u003c/p\u003e\u003cp\u003eYou function will return \u003cb\u003etrue\u003c/b\u003e for \u003ctt\u003e[1,2,1]\u003c/tt\u003e or \u003ctt\u003e[2,7,2; 6,9,6; 2,7,2]\u003c/tt\u003e . But it should return \u003cb\u003efalse\u003c/b\u003e for \u003ctt\u003e[1,2,3]\u003c/tt\u003e or \u003ctt\u003e[2,7,2; 6,9,6; 3,5,3]\u003c/tt\u003e .\u003c/p\u003e","function_template":"function y = isPalindrome(x)\r\n    y = true;\r\nend","test_suite":"%%\r\nx = [4,5,5,4];\r\ny_correct = true;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx =ones(4);\r\ny_correct = true;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx = [2,7,2; 6,9,6; 2,7,2];\r\ny_correct = true;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx = [1,2,3];\r\ny_correct = false;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx = [2,7,2; 6,9,6; 3,5,3];\r\ny_correct = false;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":25354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":135,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2016-10-05T20:25:20.000Z","updated_at":"2026-03-12T16:10:38.000Z","published_at":"2016-10-05T20:25:20.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\u003eCheck if a matrix is a palindrome both vertically and horizontally.\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 function will return\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\u003etrue\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[1,2,1]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2,7,2; 6,9,6; 2,7,2]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e . But it should return\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\u003efalse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[1,2,3]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2,7,2; 6,9,6; 3,5,3]\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\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":44854,"title":"Alternating 1´s and 0´s in a matrix","description":"Given an odd number n, write a function that creates a matrix y with dimension nxn alternating 1's and 0's, and starting with 1 in the center of the matrix. For example, for n=3 one should get:\r\n\r\n  y = [0 0 0 ; 0 1 0; 0 0 0]\r\n","description_html":"\u003cp\u003eGiven an odd number n, write a function that creates a matrix y with dimension nxn alternating 1's and 0's, and starting with 1 in the center of the matrix. For example, for n=3 one should get:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ey = [0 0 0 ; 0 1 0; 0 0 0]\r\n\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [0 0 0; 0 1 0; 0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [1 1 1 1 1; 1 0 0 0 1; 1 0 1 0 1; 1 0 0 0 1; 1 1 1 1 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 7;\r\ny_correct = [0 0 0 0 0 0 0; 0 1 1 1 1 1 0; 0 1 0 0 0 1 0; 0 1 0 1 0 1 0; 0 1 0 0 0 1 0; 0 1 1 1 1 1 0; 0 0 0 0 0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":274816,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-02-18T17:53:18.000Z","updated_at":"2025-12-31T12:22:19.000Z","published_at":"2019-02-18T17:53:18.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 an odd number n, write a function that creates a matrix y with dimension nxn alternating 1's and 0's, and starting with 1 in the center of the matrix. For example, for n=3 one should get:\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 ; 0 1 0; 0 0 0]]]\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":2290,"title":"チェッカーボードを作ろう","description":"整数 n が与えられた時、以下の様な1と0を含むn×nの行列を作成しましょう。a(1,1) は1にする必要があります。\r\n\r\n例：\r\n\r\n 入力  n = 5\r\n 出力 a が [1 0 1 0 1\r\n              0 1 0 1 0\r\n              1 0 1 0 1\r\n              0 1 0 1 0 \r\n              1 0 1 0 1]\r\n\r\n* (英語版) Problem 4. Make a checkerboard matrix\r\n\u003chttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003e","description_html":"\u003cp\u003e整数 n が与えられた時、以下の様な1と0を含むn×nの行列を作成しましょう。a(1,1) は1にする必要があります。\u003c/p\u003e\u003cp\u003e例：\u003c/p\u003e\u003cpre\u003e 入力  n = 5\r\n 出力 a が [1 0 1 0 1\r\n              0 1 0 1 0\r\n              1 0 1 0 1\r\n              0 1 0 1 0 \r\n              1 0 1 0 1]\u003c/pre\u003e\u003cul\u003e\u003cli\u003e(英語版) Problem 4. Make a checkerboard matrix \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function a = checkerboard(x)\r\n  a = ones(n);\r\nend","test_suite":"%%\r\nn = 5;\r\na = [1 0 1 0 1;\r\n     0 1 0 1 0;\r\n     1 0 1 0 1;\r\n     0 1 0 1 0;\r\n     1 0 1 0 1];\r\nassert(isequal(a,checkerboard(n)))\r\n\r\n%%\r\nn = 4;\r\na = [1 0 1 0;\r\n     0 1 0 1;\r\n     1 0 1 0;\r\n     0 1 0 1];\r\nassert(isequal(a,checkerboard(n)))","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":11824,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":400,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":36,"created_at":"2014-04-18T01:33:12.000Z","updated_at":"2026-03-16T19:04:58.000Z","published_at":"2014-04-18T01:33:17.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\u003e整数 n が与えられた時、以下の様な1と0を含むn×nの行列を作成しましょう。a(1,1) は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\u003e例：\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[ 入力  n = 5\\n 出力 a が [1 0 1 0 1\\n              0 1 0 1 0\\n              1 0 1 0 1\\n              0 1 0 1 0 \\n              1 0 1 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=\\\"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(英語版) Problem 4. Make a checkerboard matrix\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/4-make-a-checkerboard-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":44446,"title":"Add a vector to a matrix","description":"Given a matrix |mat| of size |mXn| and a row vector |v| of size |1Xs|, return a matrix with |m+1| rows that conatains |mat| over |v|.\r\nThe number of columns is the larger between |n| and |s|.\r\n\r\nIf |s\u003en|, the matrix is padded with |Inf|.\r\n\r\nIf |n\u003es|, the vector is padded with |-Inf|.\r\n\r\nExamples:\r\n\r\n  inputs:\r\n  mat = [1  2\r\n         3  4]\r\n  v   = [5  6  7  8]\r\n\r\n  output:\r\n  comb = [1   2   Inf  Inf\r\n          3   4   Inf  Inf\r\n          5   6   7    8  ]\r\n\r\n  inputs:\r\n  mat = [1   2   3   4   5\r\n         6   7   8   9   10]\r\n  v   = [11  12]\r\n\r\n  output:\r\n  comb = [1    2     3     4     5\r\n          6    7     8     9     10\r\n          11   12   -Inf  -Inf  -Inf]","description_html":"\u003cp\u003eGiven a matrix \u003ctt\u003emat\u003c/tt\u003e of size \u003ctt\u003emXn\u003c/tt\u003e and a row vector \u003ctt\u003ev\u003c/tt\u003e of size \u003ctt\u003e1Xs\u003c/tt\u003e, return a matrix with \u003ctt\u003em+1\u003c/tt\u003e rows that conatains \u003ctt\u003emat\u003c/tt\u003e over \u003ctt\u003ev\u003c/tt\u003e.\r\nThe number of columns is the larger between \u003ctt\u003en\u003c/tt\u003e and \u003ctt\u003es\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003es\u0026gt;n\u003c/tt\u003e, the matrix is padded with \u003ctt\u003eInf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003en\u0026gt;s\u003c/tt\u003e, the vector is padded with \u003ctt\u003e-Inf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1  2\r\n       3  4]\r\nv   = [5  6  7  8]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1   2   Inf  Inf\r\n        3   4   Inf  Inf\r\n        5   6   7    8  ]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1   2   3   4   5\r\n       6   7   8   9   10]\r\nv   = [11  12]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1    2     3     4     5\r\n        6    7     8     9     10\r\n        11   12   -Inf  -Inf  -Inf]\r\n\u003c/pre\u003e","function_template":"function comb = addVecToMat(mat, v)\r\n  comb = [mat; v];\r\nend","test_suite":"%%\r\nfiletext = fileread('addVecToMat.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nmat = ones(2);\r\nv   = 1:3;\r\ncomb_correct = [1 1 inf; 1 1 inf; 1 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3, 4);\r\nv   = [2 3];\r\ncomb_correct = [ones(3,4); 2 3 -inf -inf];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(2);\r\nv   = [2 3];\r\ncomb_correct = [1 1; 1 1; 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3);\r\nv   = 1:6;\r\ncomb_correct = [repmat([ones(1,3) inf(1,3)], 3, 1); 1:6];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":186,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-11T00:10:48.000Z","updated_at":"2025-11-29T16:14:21.000Z","published_at":"2017-12-11T00:10: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\",\"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 matrix\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a row vector\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1Xs\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return a matrix 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em+1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e rows that conatains\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e over\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The number of columns is the larger between\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:rFonts w:cs=\\\"monospace\\\"/\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u0026gt;n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the matrix is padded 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInf\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u0026gt;s\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the vector is padded 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e-Inf\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\u003eExamples:\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[inputs:\\nmat = [1  2\\n       3  4]\\nv   = [5  6  7  8]\\n\\noutput:\\ncomb = [1   2   Inf  Inf\\n        3   4   Inf  Inf\\n        5   6   7    8  ]\\n\\ninputs:\\nmat = [1   2   3   4   5\\n       6   7   8   9   10]\\nv   = [11  12]\\n\\noutput:\\ncomb = [1    2     3     4     5\\n        6    7     8     9     10\\n        11   12   -Inf  -Inf  -Inf]]]\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":413,"title":"Back to basics 23 - Triangular matrix","description":"Covering some basic topics I haven't seen elsewhere on Cody.\r\n\r\nGiven an input matrix, return a matrix with all elements above and to the right of the main diagonal set to zero. Example:\r\n\r\n  input = [ 1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]\r\n  output = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1]\r\n","description_html":"\u003cp\u003eCovering some basic topics I haven't seen elsewhere on Cody.\u003c/p\u003e\u003cp\u003eGiven an input matrix, return a matrix with all elements above and to the right of the main diagonal set to zero. Example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput = [ 1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]\r\noutput = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1]\r\n\u003c/pre\u003e","function_template":"function y = triangle(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = ones(4,4);\r\ny_correct = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1];\r\nassert(isequal(triangle(x),y_correct))\r\n\r\n%%\r\nx = ones(5,5);\r\ny_correct = [1 0 0 0 0; 1 1 0 0 0; 1 1 1 0 0; 1 1 1 1 0; 1 1 1 1 1];\r\nassert(isequal(triangle(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:16,[4,4]);\r\ny_correct = [1 2 3 4; 0 6 7 8; 0 0 11 12; 0 0 0 16]';\r\nassert(isequal(triangle(x),y_correct))\r\n\r\n%%\r\nx = [0 1 2 3; 0 0 1 2; 0 0 0 1; 0 0 0 0];\r\ny_correct = zeros(4);\r\nassert(isequal(triangle(x),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":3,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1122,"test_suite_updated_at":"2017-02-24T16:49:14.000Z","rescore_all_solutions":false,"group_id":19,"created_at":"2012-02-25T21:46:25.000Z","updated_at":"2026-03-15T18:45:01.000Z","published_at":"2012-02-25T21:46:25.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\u003eCovering some basic topics I haven't seen elsewhere on Cody.\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 an input matrix, return a matrix with all elements above and to the right of the main diagonal set to zero. 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[input = [ 1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]\\noutput = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1]]]\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":45172,"title":"Cross (\"+\") flag returns","description":"Given two numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\r\nGiven two even numbers, [p, q], return a matrix of size p x q which has the centre band of two numbers set as 1. However, there must be at least four zeros on the outer corners of the matrix.\r\nFor example, [m, n] = [3, 3] would return:\r\n[0,1,0;\r\n1,1,1;\r\n0,1,0];\r\nAnd for even numbers: [p, q] = [4, 3] would return\r\n[0,1,0;\r\n1,1,1;\r\n1,1,1;\r\n0,1,0];","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: 317.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 158.517px; transform-origin: 407px 158.517px; vertical-align: baseline; \"\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: 383px 8px; transform-origin: 383px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 279.5px 8px; transform-origin: 279.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two even numbers, [p, q], return a matrix of size p x q which has the centre band of\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003etwo\u003c/span\u003e\u003c/span\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: 90px 8px; transform-origin: 90px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e numbers set as 1. However, there must be at least four zeros on the outer corners 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: 127.5px 8px; transform-origin: 127.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, [m, n] = [3, 3] would return:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; 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 30.65px; transform-origin: 404px 30.65px; 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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[0,1,0;\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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1,1,1;\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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e0,1,0];\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: 155px 8px; transform-origin: 155px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAnd for even numbers: [p, q] = [4, 3] would return\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 404px 40.8667px; 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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[0,1,0;\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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1,1,1;\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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1,1,1;\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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e0,1,0];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = crossFlag2(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nm = 2; n = 2;\r\ny_correct = zeros(2,2);\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 3; n = 3;\r\ny_correct = [0, 1, 0; 1, 1, 1; 0, 1, 0];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 4; n = 4;\r\ny_correct = [0,1,1,0;\r\n             1,1,1,1;\r\n             1,1,1,1;\r\n             0,1,1,0];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 5; n = 3;\r\ny_correct = [0, 1, 0; 0, 1, 0; 1, 1, 1; 0, 1, 0; 0, 1, 0];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 3; n = 1;\r\ny_correct = ones(m,n);\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 16; n = 8;\r\ny_correct = [zeros(7,3),ones(7,2),zeros(7,3);ones(2,8);zeros(7,3),ones(7,2),zeros(7,3)];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 7; n = 280;\r\ny_correct = [zeros(3,139), ones(3,2), zeros(3,139); ones(1,280); zeros(3,139), ones(3,2), zeros(3,139)];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 1; n = 1;\r\ny_correct = 1;\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 0; n = 0;\r\ny_correct =[];\r\nassert(isequal(crossFlag2(m, n),y_correct));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":8,"created_by":157354,"edited_by":223089,"edited_at":"2022-11-25T07:01:15.000Z","deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2022-11-25T07:01:15.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-11T20:16:53.000Z","updated_at":"2026-03-11T12:00:48.000Z","published_at":"2019-10-11T20:16:53.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eGiven two numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\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\u003eGiven two even numbers, [p, q], return a matrix of size p x q which has the centre band 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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003etwo\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e numbers set as 1. However, there must be at least four zeros on the outer corners 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, [m, n] = [3, 3] would return:\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,0;\\n1,1,1;\\n0,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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnd for even numbers: [p, q] = [4, 3] would return\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,0;\\n1,1,1;\\n1,1,1;\\n0,1,0];]]\u003e\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":44063,"title":"Make a rainbow matrix (follow-up to checkerboard matrix)","description":"Given an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.\r\n\r\nThis is a follow-up question to Cody Challenge CheckerBoard Problem at \u003chttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003e\r\n\r\nFor n=10 \r\n\r\n Input  n = 10\r\n Output a is\r\n  [0   1   2   3   4   5   6   7   8   9\r\n   1   2   3   4   5   6   7   8   9   8\r\n   2   3   4   5   6   7   8   9   8   7\r\n   3   4   5   6   7   8   9   8   7   6\r\n   4   5   6   7   8   9   8   7   6   5\r\n   5   6   7   8   9   8   7   6   5   4\r\n   6   7   8   9   8   7   6   5   4   3\r\n   7   8   9   8   7   6   5   4   3   2\r\n   8   9   8   7   6   5   4   3   2   1\r\n   9   8   7   6   5   4   3   2   1   0]\r\n   ","description_html":"\u003cp\u003eGiven an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.\u003c/p\u003e\u003cp\u003eThis is a follow-up question to Cody Challenge CheckerBoard Problem at \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/a\u003e\u003c/p\u003e\u003cp\u003eFor n=10\u003c/p\u003e\u003cpre\u003e Input  n = 10\r\n Output a is\r\n  [0   1   2   3   4   5   6   7   8   9\r\n   1   2   3   4   5   6   7   8   9   8\r\n   2   3   4   5   6   7   8   9   8   7\r\n   3   4   5   6   7   8   9   8   7   6\r\n   4   5   6   7   8   9   8   7   6   5\r\n   5   6   7   8   9   8   7   6   5   4\r\n   6   7   8   9   8   7   6   5   4   3\r\n   7   8   9   8   7   6   5   4   3   2\r\n   8   9   8   7   6   5   4   3   2   1\r\n   9   8   7   6   5   4   3   2   1   0]\u003c/pre\u003e","function_template":"function a = rainBowMatrix(n)\r\n  a = magic(n);\r\nend","test_suite":"%%\r\nn = 2;\r\na_correct = [0 1;\r\n             1 0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 3;\r\na_correct = [0 1 2;\r\n             1 2 1;\r\n             2 1 0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 4;\r\na_correct = [0   1   2   3;\r\n             1   2   3   2;\r\n             2   3   2   1;\r\n             3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 5;\r\na_correct = [0   1   2   3   4;\r\n             1   2   3   4   3;\r\n             2   3   4   3   2;\r\n             3   4   3   2   1;\r\n             4   3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 6;\r\na_correct = [0   1   2   3   4   5;\r\n             1   2   3   4   5   4;\r\n             2   3   4   5   4   3;\r\n             3   4   5   4   3   2;\r\n             4   5   4   3   2   1;\r\n             5   4   3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 8;\r\na_correct = [0   1   2   3   4   5   6   7;\r\n             1   2   3   4   5   6   7   6;\r\n             2   3   4   5   6   7   6   5;\r\n             3   4   5   6   7   6   5   4;\r\n             4   5   6   7   6   5   4   3;\r\n             5   6   7   6   5   4   3   2;\r\n             6   7   6   5   4   3   2   1;\r\n             7   6   5   4   3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":115733,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2018-07-31T17:49:51.000Z","rescore_all_solutions":false,"group_id":41,"created_at":"2017-02-09T18:42:50.000Z","updated_at":"2026-02-27T13:38:30.000Z","published_at":"2017-02-09T18:50:34.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 an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.\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\u003eThis is a follow-up question to Cody Challenge CheckerBoard Problem at\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/4-make-a-checkerboard-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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 n=10\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[ Input  n = 10\\n Output a is\\n  [0   1   2   3   4   5   6   7   8   9\\n   1   2   3   4   5   6   7   8   9   8\\n   2   3   4   5   6   7   8   9   8   7\\n   3   4   5   6   7   8   9   8   7   6\\n   4   5   6   7   8   9   8   7   6   5\\n   5   6   7   8   9   8   7   6   5   4\\n   6   7   8   9   8   7   6   5   4   3\\n   7   8   9   8   7   6   5   4   3   2\\n   8   9   8   7   6   5   4   3   2   1\\n   9   8   7   6   5   4   3   2   1   0]]]\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":2254,"title":"Possible Opponents Matrix for single-elimination tournament","description":"It's tournament time!\r\n\r\nGiven a single-elimination tournament with 2^N competitors, compute the 2^N by 2^N matrix M such that M(i,j)=1 iff competitor i might play competitor j in round R, where 1\u003c=R\u003c=N.  (In each round each surviving competitor plays his \"next door neighbor\" in the bracket.)\r\n\r\nFor example, if N=1, R=1 then\r\n\r\n M =\r\n   [ 0 1\r\n     1 0]\r\n\r\nor if N=2, R=2 then\r\n\r\n M = \r\n   [ 0 0 1 1 \r\n     0 0 1 1\r\n     1 1 0 0 \r\n     1 1 0 0 ]","description_html":"\u003cp\u003eIt's tournament time!\u003c/p\u003e\u003cp\u003eGiven a single-elimination tournament with 2^N competitors, compute the 2^N by 2^N matrix M such that M(i,j)=1 iff competitor i might play competitor j in round R, where 1\u0026lt;=R\u0026lt;=N.  (In each round each surviving competitor plays his \"next door neighbor\" in the bracket.)\u003c/p\u003e\u003cp\u003eFor example, if N=1, R=1 then\u003c/p\u003e\u003cpre\u003e M =\r\n   [ 0 1\r\n     1 0]\u003c/pre\u003e\u003cp\u003eor if N=2, R=2 then\u003c/p\u003e\u003cpre\u003e M = \r\n   [ 0 0 1 1 \r\n     0 0 1 1\r\n     1 1 0 0 \r\n     1 1 0 0 ]\u003c/pre\u003e","function_template":"function [ o ] = opponents( N , R )\r\n  o=zeros(2^N);\r\nend","test_suite":"1\r\n%%\r\no=opponents(1,1);\r\nassert(isequal(o,[0 1;1 0]))\r\n2\r\n%%\r\no=opponents(2,1);\r\nassert(isequal(o,[0 1 0 0;1 0 0 0;0 0 0 1;0 0 1 0]))\r\n3\r\n%%\r\no=opponents(2,2);\r\nassert(isequal(o,[0 0 1 1;0 0 1 1;1 1 0 0 ;1 1 0 0]))\r\n4\r\n%%\r\nfor w=1:5\r\n    N=randi(5);\r\n    R=randi(N);\r\n    o=opponents(N,R);\r\n    assert(isequal(size(o),[2^N 2^N]))\r\n    for v=1:10;\r\n        i=randi(2^N);\r\n        j=randi(2^N);\r\n        q=dec2bin([i;j]-1,N)-'0';\r\n        % i might face j in round R if they are identical\r\n        % in the leftmost N-R bits, but differ in the (N-R+1)th bit\r\n        assert(o(i,j)==(1==polyval(abs(diff(q(:,1:N-R+1))),2)))\r\n    end\r\nend\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":6,"created_by":4567,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":11,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-23T17:48:43.000Z","updated_at":"2014-03-24T18:14:20.000Z","published_at":"2014-03-23T17:48:43.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\u003eIt's tournament time!\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 single-elimination tournament with 2^N competitors, compute the 2^N by 2^N matrix M such that M(i,j)=1 iff competitor i might play competitor j in round R, where 1\u0026lt;=R\u0026lt;=N. (In each round each surviving competitor plays his \\\"next door neighbor\\\" in the bracket.)\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 N=1, R=1 then\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[ M =\\n   [ 0 1\\n     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\u003eor if N=2, R=2 then\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[ M = \\n   [ 0 0 1 1 \\n     0 0 1 1\\n     1 1 0 0 \\n     1 1 0 0 ]]]\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":44468,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":163,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T22:09:37.000Z","updated_at":"2026-03-11T17:00:04.000Z","published_at":"2017-12-24T22:09:37.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 a positive integer\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty 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\u003eExamples:\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[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\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":312,"title":"Better bullseye matrix","description":"\u003chttp://www.mathworks.com/matlabcentral/cody/problems/18-bullseye-matrix Problem 18\u003e asks to create a bullseye matrix like this:\r\n\r\n  [ 3 3 3 3 3\r\n    3 2 2 2 3 \r\n    3 2 1 2 3\r\n    3 2 2 2 3 \r\n    3 3 3 3 3 ] \r\n\r\nBut I think a better one would look like this:\r\n\r\n  [ 5 4 3 4 5\r\n    4 3 2 3 4\r\n    3 2 1 2 3\r\n    4 3 2 3 4\r\n    5 4 3 4 5 ]\r\n\r\nThus given n (always odd), return output a that has concentric rings of the numbers 1 through n around the center point. \r\n","description_html":"\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/18-bullseye-matrix\"\u003eProblem 18\u003c/a\u003e asks to create a bullseye matrix like this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[ 3 3 3 3 3\r\n  3 2 2 2 3 \r\n  3 2 1 2 3\r\n  3 2 2 2 3 \r\n  3 3 3 3 3 ] \r\n\u003c/pre\u003e\u003cp\u003eBut I think a better one would look like this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[ 5 4 3 4 5\r\n  4 3 2 3 4\r\n  3 2 1 2 3\r\n  4 3 2 3 4\r\n  5 4 3 4 5 ]\r\n\u003c/pre\u003e\u003cp\u003eThus given n (always odd), return output a that has concentric rings of the numbers 1 through n around the center point.\u003c/p\u003e","function_template":"function a = bullseye(n)\r\n  a = zeros(n);\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(bullseye(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = [3 2 3; 2 1 2; 3 2 3];\r\nassert(isequal(bullseye(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [5     4     3     4     5; 4     3     2     3     4; 3     2     1     2     3; 4     3     2     3     4;     5     4     3     4     5];\r\nassert(isequal(bullseye(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":249,"test_suite_updated_at":"2012-02-12T06:44:11.000Z","rescore_all_solutions":false,"group_id":18,"created_at":"2012-02-12T06:44:11.000Z","updated_at":"2026-02-10T21:45:27.000Z","published_at":"2012-02-12T06:44: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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/18-bullseye-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 18\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asks to create a bullseye matrix like this:\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[[ 3 3 3 3 3\\n  3 2 2 2 3 \\n  3 2 1 2 3\\n  3 2 2 2 3 \\n  3 3 3 3 3 ]]]\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\u003eBut I think a better one would look like this:\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[[ 5 4 3 4 5\\n  4 3 2 3 4\\n  3 2 1 2 3\\n  4 3 2 3 4\\n  5 4 3 4 5 ]]]\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\u003eThus given n (always odd), return output a that has concentric rings of the numbers 1 through n around the center point.\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":45171,"title":"Squares in Squares - Concentric Squares","description":"Given a number, n, create an n x n sized matrix with concentric squares of 1s from the outside in. There should be a gap between each square (represented by 0s). \r\n\r\nIf n is even, the centre of the matrix should be a 2 x 2 square of 0s or 1s, if it is odd it should be a 1 x 1 square. \r\n\r\nThe function should return the square matrix, S, and the number of squares, Sn, (in some cases this may only be one).\r\n\r\n  e.g. n = 7\r\n    1 1 1 1 1 1 1\r\n    1 0 0 0 0 0 1\r\n    1 0 1 1 1 0 1\r\n    1 0 1 0 1 0 1\r\n    1 0 1 1 1 0 1\r\n    1 0 0 0 0 0 1\r\n    1 1 1 1 1 1 1\r\n\r\n\r\n","description_html":"\u003cp\u003eGiven a number, n, create an n x n sized matrix with concentric squares of 1s from the outside in. There should be a gap between each square (represented by 0s).\u003c/p\u003e\u003cp\u003eIf n is even, the centre of the matrix should be a 2 x 2 square of 0s or 1s, if it is odd it should be a 1 x 1 square.\u003c/p\u003e\u003cp\u003eThe function should return the square matrix, S, and the number of squares, Sn, (in some cases this may only be one).\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ee.g. n = 7\r\n  1 1 1 1 1 1 1\r\n  1 0 0 0 0 0 1\r\n  1 0 1 1 1 0 1\r\n  1 0 1 0 1 0 1\r\n  1 0 1 1 1 0 1\r\n  1 0 0 0 0 0 1\r\n  1 1 1 1 1 1 1\r\n\u003c/pre\u003e","function_template":"function [S,Sn] = squaresinsquares(n)\r\n  S = ones(n);\r\nend","test_suite":"%%\r\nn = 7;\r\nS_correct = ...\r\n   [1 1 1 1 1 1 1;\r\n    1 0 0 0 0 0 1;\r\n    1 0 1 1 1 0 1;\r\n    1 0 1 0 1 0 1;\r\n    1 0 1 1 1 0 1;\r\n    1 0 0 0 0 0 1;\r\n    1 1 1 1 1 1 1];\r\nSn_correct = 2;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 2;\r\nS_correct = [1 1; 1 1];\r\nSn_correct = 1;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 1;\r\nS_correct = 1;\r\nSn_correct = 1;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 10;\r\nSn_correct = 3;\r\n[~,Sn] = squaresinsquares(n);\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 6;\r\nS_correct = ...\r\n   [1 1 1 1 1 1;\r\n    1 0 0 0 0 1;\r\n    1 0 1 1 0 1;\r\n    1 0 1 1 0 1;\r\n    1 0 0 0 0 1;\r\n    1 1 1 1 1 1];\r\nSn_correct = 2;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":162339,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-11T10:40:01.000Z","updated_at":"2019-10-11T10:40:01.000Z","published_at":"2019-10-11T10:40:01.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 number, n, create an n x n sized matrix with concentric squares of 1s from the outside in. There should be a gap between each square (represented by 0s).\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\u003eIf n is even, the centre of the matrix should be a 2 x 2 square of 0s or 1s, if it is odd it should be a 1 x 1 square.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe function should return the square matrix, S, and the number of squares, Sn, (in some cases this may only be one).\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[e.g. n = 7\\n  1 1 1 1 1 1 1\\n  1 0 0 0 0 0 1\\n  1 0 1 1 1 0 1\\n  1 0 1 0 1 0 1\\n  1 0 1 1 1 0 1\\n  1 0 0 0 0 0 1\\n  1 1 1 1 1 1 1]]\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":611,"title":"surrounded matrix","description":"With a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:\r\n\r\n  A = [1 2 3\r\n       3 2 1]\r\n  \r\n  B = [1 1 1 1 1\r\n       1 1 2 3 1\r\n       1 3 2 1 1\r\n       1 1 1 1 1]\r\n\r\nor\r\n\r\n  A = 4\r\n\r\n  B = [ 1 1 1\r\n        1 4 1\r\n        1 1 1]","description_html":"\u003cp\u003eWith a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [1 2 3\r\n     3 2 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eB = [1 1 1 1 1\r\n     1 1 2 3 1\r\n     1 3 2 1 1\r\n     1 1 1 1 1]\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = 4\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eB = [ 1 1 1\r\n      1 4 1\r\n      1 1 1]\r\n\u003c/pre\u003e","function_template":"function B = surrounded(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = ones(3);\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = [3 3 3;3 3 3];\r\ny_correct = [1 1 1 1 1;1 3 3 3 1; 1 3 3 3 1; 1 1 1 1 1];\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = ones(3,4);\r\ny_correct = ones(5,6);\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = [0];\r\ny_correct = ones(3); y_correct(2,2) = 0;\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\ny_correct = [1 1 1 1 1; 1 1 2 3 1; ...\r\n    1 4 5 6 1; 1 7 8 9 1; 1 1 1 1 1]';\r\nassert(isequal(surrounded(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":3062,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1453,"test_suite_updated_at":"2017-02-24T16:54:28.000Z","rescore_all_solutions":false,"group_id":19,"created_at":"2012-04-22T09:21:22.000Z","updated_at":"2026-04-02T19:15:31.000Z","published_at":"2012-04-22T09:24:58.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\u003eWith a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:\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[A = [1 2 3\\n     3 2 1]\\n\\nB = [1 1 1 1 1\\n     1 1 2 3 1\\n     1 3 2 1 1\\n     1 1 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\u003eor\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[A = 4\\n\\nB = [ 1 1 1\\n      1 4 1\\n      1 1 1]]]\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":2303,"title":"Compute Hamming distances between each pair of rows from two input matrices","description":"For two input matrices _u_ ( _n_ x _uCols_ ) and _v_ ( _n_ x _vCols_ ) of numbers in range [0..255] (8-bit), such that each column represents an  _(8 x n)_-dimensional binary vector, calculate _uCols_ x _vCols_ matrix with each entry _(i,j)_ being a Hamming distance between _i_ -th and _j_ -th column from inputs _u_ and _v_ respectively.\r\n","description_html":"\u003cp\u003eFor two input matrices \u003ci\u003eu\u003c/i\u003e ( \u003ci\u003en\u003c/i\u003e x \u003ci\u003euCols\u003c/i\u003e ) and \u003ci\u003ev\u003c/i\u003e ( \u003ci\u003en\u003c/i\u003e x \u003ci\u003evCols\u003c/i\u003e ) of numbers in range [0..255] (8-bit), such that each column represents an  \u003ci\u003e(8 x n)\u003c/i\u003e-dimensional binary vector, calculate \u003ci\u003euCols\u003c/i\u003e x \u003ci\u003evCols\u003c/i\u003e matrix with each entry \u003ci\u003e(i,j)\u003c/i\u003e being a Hamming distance between \u003ci\u003ei\u003c/i\u003e -th and \u003ci\u003ej\u003c/i\u003e -th column from inputs \u003ci\u003eu\u003c/i\u003e and \u003ci\u003ev\u003c/i\u003e respectively.\u003c/p\u003e","function_template":"function y = hammings(u, v)\r\n  y = zeros(size(u,2),size(v,2));\r\nend","test_suite":"%% test 0\r\nq  = [0 \r\n      0];\r\ndb = [0 0\r\n      0 0];\r\nhamming_distances = [0 0];\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n\r\n%% test 1\r\nq  = 128;\r\ndb = 4;\r\nhamming_distances = 2;\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n\r\n\r\n%% test 2\r\nq  = [  0   0 0 \r\n      128 128 0];\r\ndb = [128 255 0\r\n        0   0 0];\r\nhamming_distances = [2 9 1; 2 9 1; 1 8 0];\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n\r\n\r\n%% test 3\r\nq  = [128  \r\n      128];\r\ndb = [255 0\r\n      255 0];\r\nhamming_distances = [14 2];\r\nassert(isequal(hammings(q, db), hamming_distances));\r\n\r\n\r\n%% test 4\r\nq  = [  0   0 0 \r\n      128 128 0];\r\ndb = [128 255\r\n        0   0];\r\nhamming_distances = [2 9; 2 9; 1 8];\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":6084,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-01T17:29:58.000Z","updated_at":"2014-05-01T17:42:00.000Z","published_at":"2014-05-01T17:42:00.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 two input matrices\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\u003eu\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 x\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\u003euCols\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\u003ev\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 x\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\u003evCols\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) of numbers in range [0..255] (8-bit), such that each column represents an \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\u003e(8 x n)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-dimensional binary vector, calculate\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\u003euCols\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e x\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\u003evCols\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix with each entry\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\u003e(i,j)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e being a Hamming distance between\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\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e -th 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\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e -th column from 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\u003eu\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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e respectively.\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":58822,"title":"Make a \"better\" checkerboard matrix","description":"This problem seeks to expand the task in Cody Problem 4 by allowing for the creation of checkerboard matrices that can be rectangular and have squares of 0s and 1s that are larger than a single element, 1x1 (i.e. 2x2, 3x3, etc).\r\nThe result is a rectangular checkerboard where the scale of the squares relative to the board can be manipulated.\r\nFor this problem, the given values are height (h), width (w), and size of squares (n), and the first square should be 1s.\r\nExample:\r\nh = 6\r\nw = 4\r\nn = 2\r\nsolution = \r\n            1     1     0     0\r\n            1     1     0     0\r\n            0     0     1     1\r\n            0     0     1     1\r\n            1     1     0     0\r\n            1     1     0     0\r\nNote, it is possible for there to be conflicts between the dimensions of the checkerboard and the size of the squares. For example, the size of the squares must be smaller than both the height and width dimensions (n\u003cheight \u0026\u0026 n\u003cwidth). There are other possibilities for dimensional conflicts as well. For the sake of this problem, the test suite values/dimensions will be agreeable; in the future, there will be another problem for handling the challenge of disagreeable dimensions.\r\n\r\n*** This exercise has applications for image manipulation as the resulting checkerboard matrix can be used for image operations like masking and filtering. The height and width values translate to the pixel height and width of an image and square size (n) can be interpreted as a block or grain size. Another reintepretation of this problem in comparison to the simpler checkerboard matrix problem is that the solution to this problem produces checkerboard matrices of variable resolution.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 584.375px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 292.188px; transform-origin: 407.5px 292.188px; vertical-align: baseline; \"\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: 384.5px 21px; text-align: left; transform-origin: 384.5px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis problem seeks to expand the task in \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCody Problem 4\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e by allowing for the creation of checkerboard matrices that can be rectangular and have squares of 0s and 1s that are larger than a single element, 1x1 (i.e. 2x2, 3x3, etc).\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe result is a rectangular checkerboard where the scale of the squares relative to the board can be manipulated.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFor this problem, the given values are height (h), width (w), and size of squares (n), and the first square should be 1s.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 204.375px; 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: 404.5px 102.188px; transform-origin: 404.5px 102.188px; 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.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eh = 6\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ew = 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003en = 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003esolution = \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            0     0     1     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            0     0     1     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 84px; 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: 384.5px 42px; text-align: left; transform-origin: 384.5px 42px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eNote, it is possible for there to be conflicts between the dimensions of the checkerboard and the size of the squares. For example, the size of the squares must be smaller than both the height and width dimensions (n\u0026lt;height \u0026amp;\u0026amp; n\u0026lt;width). There are other possibilities for dimensional conflicts as well. For the sake of this problem, the test suite values/dimensions will be agreeable; in the future, there will be another problem for handling the challenge of disagreeable dimensions.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 105px; 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: 384.5px 52.5px; text-align: left; transform-origin: 384.5px 52.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e*** This exercise has applications for image manipulation as the resulting checkerboard matrix can be used for image operations like masking and filtering. The height and width values translate to the pixel height and width of an image and square size (n) can be interpreted as a block or grain size. Another reintepretation of this problem in comparison to the simpler checkerboard matrix problem is that the solution to this problem produces checkerboard matrices of variable resolution.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function output = checkermatrix(h,w,n)\r\noutput = zeros(h,w);\r\n\r\nend\r\n\r\n        ","test_suite":"%%\r\nfiletext = fileread('checkermatrix.m');\r\nassert(isempty(strfind(filetext, 'checkerboard')),'checkerboard() forbidden')\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp() forbidden')\r\nassert(isempty(strfind(filetext, 'regexprep')),'regexprep() forbidden')\r\n\r\n%%\r\nh = 3;\r\nw = 3;\r\nn = 1;\r\nsolution = [1 0 1; 0 1 0; 1 0 1];\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 10;\r\nw = 10;\r\nn = 2;\r\nsolution = [1     1     0     0     1     1     0     0     1     1;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            1     1     0     0     1     1     0     0     1     1];\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 10;\r\nw = 10;\r\nn = 10;\r\nsolution = ones(n);\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 6;\r\nw = 4;\r\nn = 2;\r\nsolution = [1     1     0     0;\r\n            1     1     0     0;\r\n            0     0     1     1;\r\n            0     0     1     1;\r\n            1     1     0     0;\r\n            1     1     0     0];\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 6;\r\nw = 3;\r\nn = 3;\r\nsolution = [1     1     1;\r\n            1     1     1;\r\n            1     1     1;\r\n            0     0     0;\r\n            0     0     0;\r\n            0     0     0];\r\nassert(isequal(checkermatrix(h,w,n),solution))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":3499438,"edited_by":3499438,"edited_at":"2023-11-05T07:19:37.000Z","deleted_by":null,"deleted_at":null,"solvers_count":11,"test_suite_updated_at":"2023-08-10T18:28:02.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-08-07T19:53:06.000Z","updated_at":"2023-11-05T07:19:37.000Z","published_at":"2023-08-07T19:57:02.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eThis problem seeks to expand the task in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Problem 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e by allowing for the creation of checkerboard matrices that can be rectangular and have squares of 0s and 1s that are larger than a single element, 1x1 (i.e. 2x2, 3x3, etc).\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 result is a rectangular checkerboard where the scale of the squares relative to the board can be manipulated.\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 this problem, the given values are height (h), width (w), and size of squares (n), and the first square should be 1s.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[h = 6\\nw = 4\\nn = 2\\nsolution = \\n            1     1     0     0\\n            1     1     0     0\\n            0     0     1     1\\n            0     0     1     1\\n            1     1     0     0\\n            1     1     0     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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote, it is possible for there to be conflicts between the dimensions of the checkerboard and the size of the squares. For example, the size of the squares must be smaller than both the height and width dimensions (n\u0026lt;height \u0026amp;\u0026amp; n\u0026lt;width). There are other possibilities for dimensional conflicts as well. For the sake of this problem, the test suite values/dimensions will be agreeable; in the future, there will be another problem for handling the challenge of disagreeable dimensions.\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\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\u003e*** This exercise has applications for image manipulation as the resulting checkerboard matrix can be used for image operations like masking and filtering. The height and width values translate to the pixel height and width of an image and square size (n) can be interpreted as a block or grain size. Another reintepretation of this problem in comparison to the simpler checkerboard matrix problem is that the solution to this problem produces checkerboard matrices of variable resolution.\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":44469,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":482,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2017-12-24T22:09:41.000Z","updated_at":"2026-02-14T08:55:51.000Z","published_at":"2017-12-24T22:09:41.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 a positive integer\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty 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\u003eExamples:\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[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":60686,"title":"Diagonal Product of A Square Matrix","description":"For a matrix A, calculate the product of its diagonal elements. \r\n* Assume all input matrices are square \u0026 corresponding elements are integers\r\n* Keep in mind that we are looking for the product of the diagonal elements, not the trace (sum)!","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: 81px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 40.5px; transform-origin: 407px 40.5px; vertical-align: baseline; \"\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-collapse: preserve; 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: 191.75px 8px; transform-origin: 191.75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor a matrix A, calculate the product of its diagonal elements. \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-collapse: preserve; 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: 241.958px 8px; transform-origin: 241.958px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e* Assume all input matrices are square \u0026amp; corresponding elements are integers\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-collapse: preserve; 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: 296px 8px; transform-origin: 296px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e* Keep in mind that we are looking for the product of the diagonal elements, not the trace (sum)!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = diag_prod(A)\r\n  y = A;\r\nend","test_suite":"%%\r\nA = [1 2; 3 4];\r\ny_correct = 4; % 1 x 4\r\nassert(isequal(diag_prod(A),y_correct))\r\n\r\n%%\r\nA = [1 5 6; 20 4 3; 2 101 -4];\r\ny_correct = -16; % 1 x 4 x -4\r\nassert(isequal(diag_prod(A),y_correct))\r\n\r\n%%\r\nA = zeros(20);\r\ny_correct = 0; % 0 x 0 x 0...\r\nassert(isequal(diag_prod(A),y_correct))\r\n\r\n%% \r\nA = ones(100);\r\ny_correct = 1;\r\nassert(isequal(diag_prod(A),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4585291,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-08-06T14:27:36.000Z","updated_at":"2026-03-21T09:10:43.000Z","published_at":"2024-08-06T14:27:36.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eFor a matrix A, calculate the product of its diagonal elements. \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\u003e* Assume all input matrices are square \u0026amp; corresponding elements are integers\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\u003e* Keep in mind that we are looking for the product of the diagonal elements, not the trace (sum)!\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":44634,"title":"Basic matrix operations using standard MATLAB commands","description":"Create the matrix:\r\n\r\n 1.0e+15 *\r\n\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\r\n\r\nFind the row vector of all column means\r\n\r\nHint: Use _logspace_ to create the matrix. Avoid looking at the test suite before writing a solution","description_html":"\u003cp\u003eCreate the matrix:\u003c/p\u003e\u003cpre\u003e 1.0e+15 *\u003c/pre\u003e\u003cpre\u003e    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\u003c/pre\u003e\u003cp\u003eFind the row vector of all column means\u003c/p\u003e\u003cp\u003eHint: Use \u003ci\u003elogspace\u003c/i\u003e to create the matrix. Avoid looking at the test suite before writing a solution\u003c/p\u003e","function_template":"function y = matrix_ls_means()\r\n  y = x;\r\nend","test_suite":"%%\r\ny_correct = mean([logspace(1,5,5);logspace(6,10,5);logspace(11,15,5)]);\r\nassert(isequal(matrix_ls_means(),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-05-09T05:37:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T05:32:41.000Z","updated_at":"2026-02-17T08:19:25.000Z","published_at":"2018-05-09T05:35:49.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\u003eCreate the matrix:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1.0e+15 *\\n\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0001    0.0010    0.0100    0.1000    1.0000]]\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\u003eFind the row vector of all column means\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\u003eHint: Use\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\u003elogspace\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to create the matrix. Avoid looking at the test suite before writing a solution\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":44546,"title":"Calculating the total earnings of a factory","description":"The row vector, prods contains the number of various products manufactured per hour. The second row vector, prices holds values for the corresponding item prices they sell the given product for. Given the factory generates operates on a 6-day work week and two 8-hour long shifts per day, find the total earnings.","description_html":"\u003cp\u003eThe row vector, prods contains the number of various products manufactured per hour. The second row vector, prices holds values for the corresponding item prices they sell the given product for. Given the factory generates operates on a 6-day work week and two 8-hour long shifts per day, find the total earnings.\u003c/p\u003e","function_template":"function earn = earnings(rate, price)\r\n    earn= (); % use your basic knowledge of matrix multiplication\r\nend","test_suite":"%%\r\nrate = [2,5,4];\r\nprice = [8,3,1];\r\ny_correct = 3360;\r\nassert(isequal(earnings(rate,price),3360))\r\n%%\r\nrate = [1,4];\r\nprice = [2,1];\r\ny_correct = 576;\r\nassert(isequal(earnings(rate,price),576))\r\n%%\r\nrate = [6 6 2 3 2 8];\r\nprice = [3 2 4 8 9 5];\r\ny_correct = 11520;\r\nassert(isequal(earnings(rate,price),11520))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-03-31T09:16:35.000Z","updated_at":"2026-02-11T11:25:03.000Z","published_at":"2018-03-31T09:16:35.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\u003eThe row vector, prods contains the number of various products manufactured per hour. The second row vector, prices holds values for the corresponding item prices they sell the given product for. Given the factory generates operates on a 6-day work week and two 8-hour long shifts per day, find the total earnings.\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":59244,"title":"nxn matrix with elements from 1:n^2","description":"input n defines the dimension of a square matrix to be filled from 1 to n^2  with 1 in upper left corner and n^2 in bottom right corner, numbers increasing from left to right across rows\r\nexamples:\r\nn=1\r\n1\r\nn=2\r\n1 2\r\n3 4\r\nn=5\r\n1  2  3  4  5\r\n6  7  8  9  10\r\n11 12 13 14 15 \r\n16 17 18 19 20 \r\n21 22 23 24 25\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 388.455px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 194.227px; transform-origin: 407.5px 194.227px; vertical-align: baseline; \"\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: 384.5px 21px; text-align: left; transform-origin: 384.5px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003einput n defines the dimension of a square matrix to be filled from 1 to n^2  with 1 in upper left corner and n^2 in bottom right corner, numbers increasing from left to right across rows\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eexamples:\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en=1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4318px; 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: 404.5px 10.2159px; transform-origin: 404.5px 10.2159px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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; text-wrap: 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en=2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8636px; 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: 404.5px 20.4318px; transform-origin: 404.5px 20.4318px; 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.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e3 4\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en=5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 102.159px; 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: 404.5px 51.0795px; transform-origin: 404.5px 51.0795px; 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.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1  2  3  4  5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e6  7  8  9  10\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e11 12 13 14 15 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e16 17 18 19 20 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4318px; 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: 0.727273px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.727273px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.727273px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.727273px; 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: 404.5px 10.2159px; text-wrap: nowrap; transform-origin: 404.5px 10.2159px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e21 22 23 24 25\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = squarematrix(n)\r\nmax=(n)^2;\r\nn=[];\r\nfor i1=1:max^(1/2):max\r\n    n=[n;i1:i1+(sf*f-1)];\r\nend\r\nend","test_suite":"%%\r\nn=1;\r\ny_correct=1;\r\nassert(isequal(squarematrix(n),y_correct))\r\n\r\n%%\r\nn=2;\r\ny_correct=[1 2;3 4];\r\nassert(isequal(squarematrix(n),y_correct))\r\n\r\n%%\r\nn=3;\r\ny_correct=[1 2 3;4 5 6;7 8 9];\r\nassert(isequal(squarematrix(n),y_correct))\r\n\r\n%%\r\nn=7;\r\ny_correct=[1     2     3     4     5     6     7;\r\n           8     9     10    11    12    13    14;\r\n           15    16    17    18    19    20    21;\r\n           22    23    24    25    26    27    28;\r\n           29    30    31    32    33    34    35;\r\n           36    37    38    39    40    41    42;\r\n           43    44    45    46    47    48    49];\r\nassert(isequal(squarematrix(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3499438,"edited_by":3499438,"edited_at":"2024-05-23T18:24:13.000Z","deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-11-30T21:12:27.000Z","updated_at":"2026-03-09T18:51:53.000Z","published_at":"2023-11-30T21:12:27.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003einput n defines the dimension of a square matrix to be filled from 1 to n^2  with 1 in upper left corner and n^2 in bottom right corner, numbers increasing from left to right across rows\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\u003eexamples:\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=1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1]]\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\u003en=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1 2\\n3 4]]\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\u003en=5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1  2  3  4  5\\n6  7  8  9  10\\n11 12 13 14 15 \\n16 17 18 19 20 \\n21 22 23 24 25]]\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\u003e\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":42346,"title":"Create a Matrix of Zeros","description":"Given an input x, create a square matrix y of zeros with x rows and x columns.","description_html":"\u003cp\u003eGiven an input x, create a square matrix y of zeros with x rows and x columns.\u003c/p\u003e","function_template":"function y = matrix_zeros(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;\r\ny_correct = [ ...\r\n     0     0  \r\n     0     0  ];\r\nassert(isequal(matrix_zeros(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = [ ...\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0\r\n     0     0     0     0     0     0];\r\nassert(isequal(matrix_zeros(x),y_correct))\r\n\r\n%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(matrix_zeros(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":44605,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":647,"test_suite_updated_at":"2015-06-17T18:04:48.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-06-01T01:15:52.000Z","updated_at":"2026-02-15T15:03:06.000Z","published_at":"2015-06-01T01:16:06.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 an input x, create a square matrix y of zeros with x rows and x columns.\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":44401,"title":"Vertical matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 8  9  3  9\r\n      9  6  5  2\r\n      2  1  9  9\r\n  \r\n  y = 2  1  3  2\r\n      8  6  5  9\r\n      9  9  9  9\r\n      9  9  9  9\r\n      8  6  5  9\r\n      2  1  3  2","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 8  9  3  9\r\n    9  6  5  2\r\n    2  1  9  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 2  1  3  2\r\n    8  6  5  9\r\n    9  9  9  9\r\n    9  9  9  9\r\n    8  6  5  9\r\n    2  1  3  2\r\n\u003c/pre\u003e","function_template":"function y = upAndDown(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0;0];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = zeros(10);\r\nx(7,4) = 1;\r\ny_correct = zeros(20,10);\r\ny_correct(10:11,4) = [1;1];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 4 3 2; 1 4 3 2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [8  9  3  9; 9  6  5  2; 2  1  9  9];\r\ny_correct = [2  1  3  2; 8  6  5  9; 9  9  9  9;\r\n             9  9  9  9; 8  6  5  9; 2  1  3  2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x; x];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x; flipud(x)];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nc = [1:3,3:-1:1]';\r\ny_correct = [c,c+3,c+6];\r\nassert(isequal(upAndDown(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":340,"test_suite_updated_at":"2018-05-13T07:02:36.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-11-12T07:18:04.000Z","updated_at":"2026-02-11T19:50:48.000Z","published_at":"2017-11-12T07:31:05.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 matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\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:\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 = 8  9  3  9\\n    9  6  5  2\\n    2  1  9  9\\n\\ny = 2  1  3  2\\n    8  6  5  9\\n    9  9  9  9\\n    9  9  9  9\\n    8  6  5  9\\n    2  1  3  2]]\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":43272,"title":"Implement zero-based indexing for Matrices","description":"Given an input vector and position (which is zero based) output the value \r\n\r\nExample:\r\n\r\nx = [1 2; 4 5] pos = [0 1] value = 5\r\n\r\nx = [1 2 3 4 5; 6 7 8 9 0] pos = [1 3] value = 9","description_html":"\u003cp\u003eGiven an input vector and position (which is zero based) output the value\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ex = [1 2; 4 5] pos = [0 1] value = 5\u003c/p\u003e\u003cp\u003ex = [1 2 3 4 5; 6 7 8 9 0] pos = [1 3] value = 9\u003c/p\u003e","function_template":"function y = zeroBasedMN(x,pos)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4 5];\r\npos  = [0 2]\r\ny_correct = 4;\r\nassert(isequal(zeroBasedMN(x,pos),y_correct))\r\n%%\r\nx = [1 2 3 4 5; 6 7 8 9 0];\r\npos = [1 3];\r\ny_correct = 9\r\nassert(isequal(zeroBasedMN(x,pos),y_correct))","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":13865,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2016-10-29T16:26:00.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-09T05:56:33.000Z","updated_at":"2026-03-31T13:17:53.000Z","published_at":"2016-10-09T05:56:33.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 an input vector and position (which is zero based) output the value\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = [1 2; 4 5] pos = [0 1] value = 5\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\u003ex = [1 2 3 4 5; 6 7 8 9 0] pos = [1 3] value = 9\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":44613,"title":"Find NaNs in the matrix","description":"Return 1s wherever there is a NaN in the input matrix","description_html":"\u003cp\u003eReturn 1s wherever there is a NaN in the input matrix\u003c/p\u003e","function_template":"function y = return_nans(x)\r\n  \r\nend","test_suite":"%%\r\nx = 0./[6 4 0 3 -9];\r\ny_correct = [0   0   1   0   0];\r\nassert(isequal(return_nans(x),y_correct))\r\n\r\n%%\r\nx = [1 1 NaN NaN];\r\ny_correct = [0 0 1 1];\r\nassert(isequal(return_nans(x),y_correct))\r\n\r\n%%\r\nx =[1 1 NaN NaN; 5,2,3,NaN];\r\ny_correct = [0 0 1 1; 0 0 0 1];\r\nassert(isequal(return_nans(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-04-17T05:48:44.000Z","updated_at":"2026-03-09T20:40:54.000Z","published_at":"2018-04-17T05:48: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\",\"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\u003eReturn 1s wherever there is a NaN in the input 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":44687,"title":"basic matrix operations: rotate and find sum of diagonal elements of the resultant matrix","description":"For given input matrix a, rotate it by 90 degrees and find the sum of the diagonals.\r\n\r\nExample:\r\nInput:\r\n\r\n  a =\r\n\r\n     1     2     3     4\r\n     5     6     7     8\r\n     8    10    12    -2\r\n    -1    -3    -5    -7\r\n\r\nOutput is: \r\n\r\n  20","description_html":"\u003cp\u003eFor given input matrix a, rotate it by 90 degrees and find the sum of the diagonals.\u003c/p\u003e\u003cp\u003eExample:\r\nInput:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea =\r\n\u003c/pre\u003e\u003cpre\u003e     1     2     3     4\r\n     5     6     7     8\r\n     8    10    12    -2\r\n    -1    -3    -5    -7\u003c/pre\u003e\u003cp\u003eOutput is:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e20\r\n\u003c/pre\u003e","function_template":"function ans = matrix_manipulation(x)\r\n  \r\nend","test_suite":"%%\r\nx = [1 2 3 4; 5 6 7 8;8 10, 12, -2;-1 -3 -5,-7];\r\ny_correct = 20;\r\nassert(isequal(matrix_manipulation(x),y_correct))\r\n\r\n%%\r\nx = ones(5).*3\r\ny_correct = 15;\r\nassert(isequal(matrix_manipulation(x),y_correct))\r\n\r\n%%\r\na=[3,2,5]\r\nx = [a;a;a];\r\ny_correct = 10;\r\nassert(isequal(matrix_manipulation(x),y_correct))\r\n\r\n%%\r\nx = [-5,25,-10;8,-18,10;-2,7,-1]\r\ny_correct = -30;\r\nassert(isequal(matrix_manipulation(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":62,"test_suite_updated_at":"2018-06-13T08:54:27.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-06-13T08:49:50.000Z","updated_at":"2026-03-02T08:56:19.000Z","published_at":"2018-06-13T08:54:27.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 given input matrix a, rotate it by 90 degrees and find the sum of the diagonals.\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: Input:\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[a =\\n\\n     1     2     3     4\\n     5     6     7     8\\n     8    10    12    -2\\n    -1    -3    -5    -7]]\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\u003eOutput 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[20]]\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":44740,"title":"New Matrix with vector addition on diagonal","description":"consider 2 vectors \r\n\r\n  x=[1 2 3]\r\n  y=[4 5 6]\r\n\r\nthen generate a new Matrix, where Addition of x \u0026 y will be diagonal Elements of the new Matrix. i.e. new Matrix will have x+y=[5 7 9] as diagonal Elements\r\n\r\n  Output =[5     6     7\r\n           6     7     8\r\n           7     8     9]","description_html":"\u003cp\u003econsider 2 vectors\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3]\r\ny=[4 5 6]\r\n\u003c/pre\u003e\u003cp\u003ethen generate a new Matrix, where Addition of x \u0026 y will be diagonal Elements of the new Matrix. i.e. new Matrix will have x+y=[5 7 9] as diagonal Elements\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eOutput =[5     6     7\r\n         6     7     8\r\n         7     8     9]\r\n\u003c/pre\u003e","function_template":"function z = addmat(x,y)\r\n  z = x+y;\r\nend","test_suite":"%%\r\nx=[1 2 3];\r\ny=[4 5 6];\r\nz_correct = [5 6 7;6 7 8;7 8 9]\r\nassert(isequal(addmat(x,y),z_correct))\r\n\r\n%%\r\nx=[10 20 30 40];\r\ny=[-10 -20 -30 -40];\r\nz_correct = [0 10 20 30;-10 0 10 20;-20 -10 0 10;-30 -20 -10 0]\r\nassert(isequal(addmat(x,y),z_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":136465,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":47,"test_suite_updated_at":"2018-10-02T13:28:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-10-02T13:24:35.000Z","updated_at":"2026-02-27T14:16:57.000Z","published_at":"2018-10-02T13:24:35.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\u003econsider 2 vectors\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=[1 2 3]\\ny=[4 5 6]]]\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\u003ethen generate a new Matrix, where Addition of x \u0026amp; y will be diagonal Elements of the new Matrix. i.e. new Matrix will have x+y=[5 7 9] as diagonal Elements\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[Output =[5     6     7\\n         6     7     8\\n         7     8     9]]]\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":1926,"title":"Unit Matrix","description":"Given n, you should return an n-by-n unit matrix.\r\nExample:\r\nIf input is n=2 then\r\n A = [ 1 0 \r\n       0 1 ]\r\nIf input is n=4 then\r\n A = [ 1 0 0 0\r\n       0 1 0 0\r\n       0 0 1 0 \r\n       0 0 0 1 ]","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: 254.6px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 127.3px; transform-origin: 407px 127.3px; vertical-align: baseline; \"\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: 152.5px 8px; transform-origin: 152.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven n, you should return an n-by-n unit 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: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\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: 58px 8px; transform-origin: 58px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf input is n=2 then\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; 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 20.4333px; transform-origin: 404px 20.4333px; 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: 44px 8.5px; tab-size: 4; transform-origin: 44px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = [ 1 0 \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: 48px 8.5px; tab-size: 4; transform-origin: 48px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 1 ]\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: 58px 8px; transform-origin: 58px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf input is n=4 then\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 404px 40.8667px; 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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = [ 1 0 0 0\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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 1 0 0\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: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 1 0 \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: 64px 8.5px; tab-size: 4; transform-origin: 64px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 1 ]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;\r\ny_correct = [1 0;0 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = [1 0 0;0 1 0; 0 0 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":18257,"edited_by":223089,"edited_at":"2022-10-31T04:49:45.000Z","deleted_by":null,"deleted_at":null,"solvers_count":512,"test_suite_updated_at":"2022-10-31T04:49:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-10-09T18:48:08.000Z","updated_at":"2026-02-09T16:23:54.000Z","published_at":"2013-10-09T18:48:08.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eGiven n, you should return an n-by-n unit 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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf input is n=2 then\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[ A = [ 1 0 \\n       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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf input is n=4 then\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[ A = [ 1 0 0 0\\n       0 1 0 0\\n       0 0 1 0 \\n       0 0 0 1 ]]]\u003e\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":46105,"title":"Find sum of numbers on the cornice of a matrix.","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; vertical-align: baseline; perspective-origin: 407px 85.5px; transform-origin: 407px 85.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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003eGiven a matrix of random integers, calculate the sum of all the integers in the cornice of the matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003eFor example if MTX = [ \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e1 3 5 6;\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003e                                     \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e4\u003c/span\u003e\u003c/span\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=\"\"\u003e 7 9 \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e2;\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003e                                     \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e5\u003c/span\u003e\u003c/span\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=\"\"\u003e 6 1 \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e3;\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003e                                    \u003c/span\u003e\u003c/span\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=\"font-weight: 700; \"\u003e 7 9 2 1\u003c/span\u003e\u003c/span\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=\"\"\u003e]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 384px 10.5px; transform-origin: 384px 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=\"\"\u003eoutput  = 1 + 3 + 5 + 6 + 4 + 2 + 5 + 3 + 7 + 9 + 2 + 1 = 48\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = sumCornice(MTX)\r\n  y = MTX;\r\nend","test_suite":"%% Test 1\r\nMTX = [ 1 3 5 6;\r\n        4 7 9 2;\r\n        5 6 1 3;\r\n        7 9 2 1];\r\ny_correct = 48;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 2\r\nMTX = [ 7     1     7     4     5\r\n     4     3     3     7     6\r\n     6     1     9     8     7\r\n     2     1     1     2     7\r\n     7     8     4     5     3];\r\ny_correct = 83;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 3\r\nMTX = [ 7     2\r\n     6     2];\r\ny_correct = 17;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 4\r\nMTX = [ 5     7     3     5     7     2     5     1\r\n     9     9     8     4     4     6     2     3\r\n     4     9     3     8     6     5     6     9\r\n     6     5     9     6     1     1     3     2\r\n     3     2     4     5     1     4     6     8\r\n     7     2     2     9     5     2     7     5\r\n     3     3     3     3     8     8     7     9\r\n     5     8     6     7     9     3     5     1];\r\ny_correct = 147;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n\r\n%% Test 5\r\nMTX = [ 4     8     9     6     5     3\r\n     1     1     2     5     4     4\r\n     9     4     3     2     1     1\r\n     1     3     2     8     3     9\r\n     7     8     2     6     2     9\r\n     8     4     8     4     2     5];\r\ny_correct = 107;\r\nassert(isequal(sumCornice(MTX),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":522328,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-08-05T18:20:14.000Z","updated_at":"2026-02-18T21:40:33.000Z","published_at":"2020-08-05T18:20:14.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\u003eGiven a matrix of random integers, calculate the sum of all the integers in the cornice 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 if MTX = [ \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1 3 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\u003e                                     \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e4\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 7 9 \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2;\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\u003e                                     \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 6 1 \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e3;\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\u003e                                    \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e 7 9 2 1\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput  = 1 + 3 + 5 + 6 + 4 + 2 + 5 + 3 + 7 + 9 + 2 + 1 = 48\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":44447,"title":"Eye Squared","description":"For a positive integer |n| create the identity matrix with |n| elements.\r\n\r\nIn case it is not possible to produce an identity matrix with exactly |n| elements, return an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n = 9\r\n  Output: I = [1 0 0\r\n               0 1 0\r\n               0 0 1]\r\n\r\n  Input:  n = 8\r\n  Output: I = []","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e create the identity matrix with \u003ctt\u003en\u003c/tt\u003e elements.\u003c/p\u003e\u003cp\u003eIn case it is not possible to produce an identity matrix with exactly \u003ctt\u003en\u003c/tt\u003e elements, return an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 9\r\nOutput: I = [1 0 0\r\n             0 1 0\r\n             0 0 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 8\r\nOutput: I = []\r\n\u003c/pre\u003e","function_template":"function I = eyeSquared(n)\r\n    I = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('eyeSquared.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 1;\r\nI_correct = 1;\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4;\r\nI_correct = [1 0; 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 9;\r\nI_correct = [1 0 0; 0 1 0; 0 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = -9;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 10;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4.1;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":234,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-11T00:36:01.000Z","updated_at":"2026-03-11T16:59:00.000Z","published_at":"2017-12-11T00:36:01.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 a positive integer\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e create the identity matrix 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements.\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 case it is not possible to produce an identity matrix with exactly\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements, return an empty 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\u003eExamples:\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[Input:  n = 9\\nOutput: I = [1 0 0\\n             0 1 0\\n             0 0 1]\\n\\nInput:  n = 8\\nOutput: I = []]]\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":1171,"title":"matrix of natural number","description":"Given a number n, create an n-by-n matrix in which the integers from 1 to n^2 resides seially as shown in the examples below.\r\n\r\nExamples:\r\n\r\n Input  n = 3\r\n Output a = [ 1 2 3\r\n              4 5 6\r\n              7 8 9 ]\r\n Input  n = 4\r\n Output a = [ 1     2     3     4\r\n              5     6     7     8\r\n              9    10    11    12\r\n              13   14    15    16]\r\n","description_html":"\u003cp\u003eGiven a number n, create an n-by-n matrix in which the integers from 1 to n^2 resides seially as shown in the examples below.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e Input  n = 3\r\n Output a = [ 1 2 3\r\n              4 5 6\r\n              7 8 9 ]\r\n Input  n = 4\r\n Output a = [ 1     2     3     4\r\n              5     6     7     8\r\n              9    10    11    12\r\n              13   14    15    16]\u003c/pre\u003e","function_template":"function y = nat_matrix(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(nat_matrix(x),y_correct))\r\n\r\n%%\r\n \r\nx = 5;\r\na = [  1 2 3 4 5; \r\n       6 7 8 9 10; \r\n      11 12 13 14 15; \r\n      16 17 18 19 20; \r\n      21 22 23 24 25];\r\nassert(isequal(a,nat_matrix(x)));\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":8433,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":295,"test_suite_updated_at":"2013-01-04T15:20:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-04T15:14:29.000Z","updated_at":"2026-02-18T09:23:26.000Z","published_at":"2013-01-04T15:15:20.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 number n, create an n-by-n matrix in which the integers from 1 to n^2 resides seially as shown in the examples below.\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\u003eExamples:\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[ Input  n = 3\\n Output a = [ 1 2 3\\n              4 5 6\\n              7 8 9 ]\\n Input  n = 4\\n Output a = [ 1     2     3     4\\n              5     6     7     8\\n              9    10    11    12\\n              13   14    15    16]]]\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":61296,"title":"Double the 2x2 Matrix","description":"In this challenge, you are given a predefined 2x2 matrix called x. Your task is to multiply every element in this matrix by 2 and return the result as y.\r\nExample:\r\nIf the input is:\r\n\r\nThe output should be:\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"baseline-shift: 0px; block-size: 267.4px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 469px 133.7px; transform-origin: 469px 133.7px; \"\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 21px; text-align: left; transform-origin: 445px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 139.267px 8px; transform-origin: 139.267px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn this challenge, you are given a predefined \u003c/span\u003e\u003c/span\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: 11.675px 8px; transform-origin: 11.675px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e2x2\u003c/span\u003e\u003c/span\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: 43.175px 8px; transform-origin: 43.175px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e matrix called \u003c/span\u003e\u003c/span\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: 3.89167px 8px; transform-origin: 3.89167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ex\u003c/span\u003e\u003c/span\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: 171.65px 8px; transform-origin: 171.65px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Your task is to multiply every element in this matrix by \u003c/span\u003e\u003c/span\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: 3.89167px 8px; transform-origin: 3.89167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e2\u003c/span\u003e\u003c/span\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: 66.5083px 8px; transform-origin: 66.5083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and return the result as \u003c/span\u003e\u003c/span\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: 3.89167px 8px; transform-origin: 3.89167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ey\u003c/span\u003e\u003c/span\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: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 31.1167px 8px; transform-origin: 31.1167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 41.6083px 8px; transform-origin: 41.6083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf the input is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 58.7px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 29.35px; text-align: left; transform-origin: 445px 29.35px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cimg class=\"imageNode\" style=\"vertical-align: baseline\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIM0lEQVRoQ+WbBYwsRRRF+bhbcF0suBM88IGQ4B7cJcHdLRCcj7sHgrsE1+DuHmxxd3fuSbp+enqrul71zPYs0y+52dnpku7bVa+ezbBRqsnY6nancKVwbrUhutprK82+qrCZ8GvqnQxL7aD2owvXC08KR5f079O1/grjd6LL+BpkbuFb4T3hT8+gh+q7ZTPyfkuZtAppF2mCyYQ1AhONqe/XE04T5hC+SrmhNtuOpv5HCPsL7tm+1+e9hAs9Yz+g794WtkuZN5W0PbIbmk1/fyhMdIr+X1hYUGA1jiVMIXyZckNttj1W/ScQDhD+zV7s2dl3++nv8YXxp9X/rwts05utc6eQtrQGfUhYR7jJM8EC+m5i4WnhVWHGmkmDgA+EXYUzc/e3sT5fLvwuTO95iRvou/OERYU3LcRZSUPxQ8RbwkqGgd9XmxmEKYUvDO070QTFfms20OL6i85F2LIQxt9NMwKL892vL1ihEMcKLRUraSzr3YS5hHdig+p6N0hDZTwnoPTRpfmX9Zn+5wXuKLBdi8Kh8bKwU+B6S3sLaawYVhiT7W4gjCbdIC10a5PqwtfZRVYS6sMn1+lLTlOet9QMsZCGHcbpMqvwrp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DCPRcgTXr5VUjjmTkRse6J6nYjItsu71trAHQzuYBk1+4/GZ2TRedh2dQAAAAASUVORK5CYII=\" data-image-state=\"image-loaded\"\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 67.6833px 8px; transform-origin: 67.6833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe output should be:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 58.7px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 29.35px; text-align: left; transform-origin: 445px 29.35px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cimg class=\"imageNode\" style=\"vertical-align: baseline\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIr0lEQVRoQ+XbB6xkVRkH8EXFihJ710UhCthj7GUVBVTElijFgr2Lisau2BFEwQ72rghiwQYC1qix94oulmCPvbf/L7mHzLvvlnNn35vFnS/5583cOfW753z9bbdhPjp/un04eHtwzHxDbNVe983sdwjuFfx16kq2m9oh7c8TnBB8L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aPDJpNC9k/LmA+lOsqoKhEoY+E98kyB6Vd8n92nzGmPSwt2TezZkTXhMrgVRDK4Nyp1UDExBsfrTAc2EzNT8X1aZffi1K8K/D3CQ0T+8ZjXrnaatx6tf0Y0xxRb8bGh7QiOcIgNlG7YpK5cc2KBdcwZqgN+alGTZBBDcosccBLaQSbrY+4XDQuBdhLY0zTUZaZMrhGwI/soo15qDqHxm1b/mwnGlitB9tvvejBGZj3whbrkkUYQkk9q2cBxTbtVQClXw3T2CqbA1ePgO0j9Q9sJI76r5pGjFsyAuOcttEa/S3gKMVFflqjSu1ZEiP8XnDzoC/5reBHlZFrPrjOGqaZ3NEntwjSvmpGuUKpP6exeAFOKXND3sGbXm9i9iilosmVVnnhKqBc2zcENGsXlapPnkT7v3FWta9lmhCLwmPyiXbqIwWA7DKLYH7oQ7guMkvvxBEnauZofuk3BS1DNSkiMIKOfM1RqmWagcg0JoXj76puK8RrYMwq+FGGMEpTmGYw8TVxJs5skVujk5yDG3Dz3AKVQQ5EFU1lmkFVEkooc9IXHZGt2lRlI3svQQYuYzXNwzSuisiuEIzK7/9XIucoNsbwpJc/D9MwiSmh+pldtDX++XVLXxSXj2zm2k3+H9T/AXW0r0VQewQcAAAAAElFTkSuQmCC\" data-image-state=\"image-loaded\"\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x; % Replace this with your code\r\nend\r\n","test_suite":"%% Test 1: Simple 2x2 Matrix\r\nx1 = [1 2; 3 4];\r\ny_correct1 = [2 4; 6 8];\r\nassert(isequal(your_fcn_name(x1), y_correct1))\r\n\r\n%% Test 2: Zero and Negatives\r\nx2 = [0 -5; 10 -1];\r\ny_correct2 = [0 -10; 20 -2];\r\nassert(isequal(your_fcn_name(x2), y_correct2))\r\n\r\n%% Test 3: Decimals\r\nx3 = [0.5 1.5; 2.5 3.5];\r\ny_correct3 = [1 3; 5 7];\r\nassert(isequal(your_fcn_name(x3), y_correct3))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":5088017,"edited_by":5088017,"edited_at":"2026-03-29T19:40:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2026-03-29T19:40:16.000Z","updated_at":"2026-04-03T16:34:17.000Z","published_at":"2026-03-29T19:40:20.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eIn this challenge, you are given a predefined \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2x2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix called \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Your task is to multiply every element in this matrix by \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and return the result as \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the input 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"53\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"77\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe output should be:\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:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"53\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"77\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.png\",\"relationshipId\":\"rId1\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image2.png\",\"relationshipId\":\"rId2\"}]},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIM0lEQVRoQ+WbBYwsRRRF+bhbcF0suBM88IGQ4B7cJcHdLRCcj7sHgrsE1+DuHmxxd3fuSbp+enqrul71zPYs0y+52dnpku7bVa+ezbBRqsnY6nancKVwbrUhutprK82+qrCZ8GvqnQxL7aD2owvXC08KR5f079O1/grjd6LL+BpkbuFb4T3hT8+gh+q7ZTPyfkuZtAppF2mCyYQ1AhONqe/XE04T5hC+SrmhNtuOpv5HCPsL7tm+1+e9hAs9Yz+g794WtkuZN5W0PbIbmk1/fyhMdIr+X1hYUGA1jiVMIXyZckNttj1W/ScQDhD+zV7s2dl3++nv8YXxp9X/rwts05utc6eQtrQGfUhYR7jJM8EC+m5i4WnhVWHGmkmDgA+EXYUzc/e3sT5fLvwuTO95iRvou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n5y6vl/jtNyPlTSy7jjfxMqp7/AJDjoOPkc+dSBEGDi+KTF3h0G7ZFj7O9KK7dFX/H6qKPx8iaAjJktUrKQxEDoNS5stylbtFaGUDGOWF00ZQlRSSGMwfDmUPs5snb+uiz5IxQa4XNSqUBnkfksVHSqVNAZkeeMirShgOP5fhWe/W+DwwmU0SxXSUPr4lGSd8zaZedIh0pDCPRcgTXr5VUjjmTkRse6J6nYjItsu71trAHQzuYBk1+4/GZ2TRedh2dQAAAAASUVORK5CYII=\",\"relationship\":null},{\"partUri\":\"/media/image2.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE0AAAA1CAYAAAAEeGYcAAAIr0lEQVRoQ+XbB6xkVRkH8EXFihJ710UhCthj7GUVBVTElijFgr2Lisau2BFEwQ72rghiwQYC1qix94oulmCPvbf/L7mHzLvvlnNn35vFnS/5583cOfW753z9bbdhPjp/un04eHtwzHxDbNVe983sdwjuFfx16kq2m9oh7c8TnBB8LnheR/9L5tlVgl8GPw7+Pccca9llhwz2gOCo1qBPz/dbNsz725QJ52Ha6zLBJYJ9WxNdIN9fExww8/wX+eytfmjKota47Vsz3m2CS3eMe3qe/SB44JQ5pzLtMRn8icEuwR9aE70z378evDC4YHBg8OLg3MF+gd8XTZsyIcY49V1Mu3yefztwTd9bu7gpTLtZBv1EcNfgPa0JbpLvJwf3bzHnyfn+3GbRV8jff9YubA3aOfmfDK7XzH+ZnjHvkefHBjcIvlszby3TCP5vBt8P9u4Y+OF59rLm+WXz9+fN5yvl75nNZ0z/dM2i1qjNqzLOp4I3Br8Ouk5ameq0fLhww7j/js1fy7TDM9DBwW7BGR2D3iLPPhr8NLh68I+mDWYX7XT7fF6UbLtL5npIsFfwr4ZpfSfNUncPiBYv/5VrwTSnxQkz2KPHBmz9ft18/1Kz8CvmbzmBE4eZ1HzHtP5GcKPgZwHtPXbSTHB8QJva76AZUnPS2GG0y87BDyctf8OGo9P+UcGLgkMm9p23O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yDG3Dz3AKVQQ5EFU1lmkFVEkooc9IXHZGt2lRlI3svQQYuYzXNwzSuisiuEIzK7/9XIucoNsbwpJc/D9MwiSmh+pldtDX++XVLXxSXj2zm2k3+H9T/AXW0r0VQewQcAAAAAElFTkSuQmCC\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44671,"title":"find number of times of occurrence of the most frequent number in a row vector","description":"In a given row vector, find the number of times a mode of a row vector has occurred\r\n\r\nexample: in [2 5 5 5 5 3], output is 4\r\n\r\n","description_html":"\u003cp\u003eIn a given row vector, find the number of times a mode of a row vector has occurred\u003c/p\u003e\u003cp\u003eexample: in [2 5 5 5 5 3], output is 4\u003c/p\u003e","function_template":"function y = num_mode(x)\r\n\r\nend","test_suite":"%%\r\nx =[2 3 3 3 5 3 3 5 5 5 5 5 5];\r\ny_correct = 7;\r\nassert(isequal(num_mode(x),y_correct))\r\n\r\n%%\r\nx =[8 8];\r\ny_correct = 2;\r\nassert(isequal(num_mode(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-31T15:30:12.000Z","updated_at":"2026-02-18T10:08:10.000Z","published_at":"2018-05-31T15:30:12.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\u003eIn a given row vector, find the number of times a mode of a row vector has occurred\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: in [2 5 5 5 5 3], output is 4\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":2350,"title":"What is Sum Of all elements of Matrix","description":"Given the matrix x, return the sum of all elements of matrix.\r\n\r\nExample:\r\n\r\n Input  x = [ 1 2 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is 24.\r\n\r\n Input  x = [ 1 NaN 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is NaN.","description_html":"\u003cp\u003eGiven the matrix x, return the sum of all elements of matrix.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  x = [ 1 2 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is 24.\u003c/pre\u003e\u003cpre\u003e Input  x = [ 1 NaN 0 0 0\r\n              0 6 9 3 3 ]\r\n Output y is NaN.\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1];\r\ny_correct = 1;\r\nassert(isequalwithequalnans(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 NaN 3 4 5 56];\r\ny_correct = NaN;\r\nassert(isequalwithequalnans(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":6,"created_by":25856,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":446,"test_suite_updated_at":"2014-09-09T14:35:09.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-06-06T07:35:17.000Z","updated_at":"2026-02-17T14:47:53.000Z","published_at":"2014-09-08T07:28:27.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 the matrix x, return the sum of all elements of 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\u003eExample:\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[ Input  x = [ 1 2 0 0 0\\n              0 6 9 3 3 ]\\n Output y is 24.\\n\\n Input  x = [ 1 NaN 0 0 0\\n              0 6 9 3 3 ]\\n Output y is NaN.]]\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":45173,"title":"Create the flag of Ramumbia","description":"The little known nation of Ramumbia has a very simple flag. It is made up of vertical stripes, Red, Green, Blue, that are equally spaced and with no gap between said stripes.\r\n\r\nThe artist that designed the flag has been very clear; \"If the flag is not divisible into three, equal, vertical segments, this flag shall not exist!\" However, bizarrely, the designer has given no guidance on the aspect ratio of the flag.\r\n\r\nYour task is to write a function which can reproduce said flag as a hypermatrix, viewable by the \"imshow\" function. The inputs to the function are the length, L and width, W of the flag, but remember, unless the width is divisible by three with no remainders, the flag will be blank (i.e. a hypermatrix of zeros of the appropriate size)","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; 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: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 103.5px; vertical-align: baseline; perspective-origin: 332px 103.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; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe little known nation of Ramumbia has a very simple flag. It is made up of vertical stripes, Red, Green, Blue, that are equally spaced and with no gap between said stripes.\u003c/span\u003e\u003c/span\u003e\u003c/div\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; transform-origin: 309px 31.5px; white-space: pre-wrap; perspective-origin: 309px 31.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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe artist that designed the flag has been very clear; \"If the flag is not divisible into three, equal, vertical segments, this flag shall not exist!\" However, bizarrely, the designer has given no guidance on the aspect ratio of the flag.\u003c/span\u003e\u003c/span\u003e\u003c/div\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; transform-origin: 309px 42px; white-space: pre-wrap; perspective-origin: 309px 42px; 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour task is to write a function which can reproduce said flag as a hypermatrix, viewable by the \"imshow\" function. The inputs to the function are the length, L and width, W of the flag, but remember, unless the width is divisible by three with no remainders, the flag will be blank (i.e. a hypermatrix of zeros of the appropriate size)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = RamumbiaFlag(L,W)\r\n  y = L*W;\r\nend","test_suite":"%%\r\nL = 1; W=3;\r\ny_correct(:,:,1) = [1,0,0]; \r\ny_correct(:,:,2) = [0,1,0]; \r\ny_correct(:,:,3) = [0,0,1]; \r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 3; W = 8;\r\ny_correct = zeros(L,W,3);\r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 10; W = 27;\r\ny_correct(:,:,1) = [ones(10,9),zeros(10,9),zeros(10,9)]; \r\ny_correct(:,:,2) = [zeros(10,9),ones(10,9),zeros(10,9)]; \r\ny_correct(:,:,3) = [zeros(10,9),zeros(10,9),ones(10,9)]; \r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 1000; W = 12119;\r\ny_correct = zeros(L,W,3);\r\nassert(isequal(RamumbiaFlag(L,W),y_correct))\r\n\r\n%%\r\nL = 100; W = 999;\r\ny_correct(:,:,1) = [ones(100,333),zeros(100,333),zeros(100,333)]; \r\ny_correct(:,:,2) = [zeros(100,333),ones(100,333),zeros(100,333)]; \r\ny_correct(:,:,3) = [zeros(100,333),zeros(100,333),ones(100,333)]; \r\nassert(isequal(RamumbiaFlag(L,W),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":5,"created_by":157354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16,"test_suite_updated_at":"2020-09-28T19:13:22.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2019-10-11T22:19:48.000Z","updated_at":"2025-11-07T03:29:59.000Z","published_at":"2019-10-11T22:37:36.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\u003eThe little known nation of Ramumbia has a very simple flag. It is made up of vertical stripes, Red, Green, Blue, that are equally spaced and with no gap between said stripes.\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 artist that designed the flag has been very clear; \\\"If the flag is not divisible into three, equal, vertical segments, this flag shall not exist!\\\" However, bizarrely, the designer has given no guidance on the aspect ratio of the flag.\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\u003eYour task is to write a function which can reproduce said flag as a hypermatrix, viewable by the \\\"imshow\\\" function. The inputs to the function are the length, L and width, W of the flag, but remember, unless the width is divisible by three with no remainders, the flag will be blank (i.e. a hypermatrix of zeros of the appropriate size)\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":412,"title":"Back to basics 22 - Rotate a matrix","description":"Covering some basic topics I haven't seen elsewhere on Cody.\r\n\r\nRotate the input matrix 90 degrees counterclockwise (e.g. [1 2; 3 4] -\u003e [2 4; 1 3]\r\n","description_html":"\u003cp\u003eCovering some basic topics I haven't seen elsewhere on Cody.\u003c/p\u003e\u003cp\u003eRotate the input matrix 90 degrees counterclockwise (e.g. [1 2; 3 4] -\u003e [2 4; 1 3]\u003c/p\u003e","function_template":"function y = rotateBy90(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2; 3 4];\r\ny_correct = [2 4; 1 3];\r\nassert(isequal(rotateBy90(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3; 4 5 6; 7 8 9];\r\ny_correct = [ 3    6    9;    2    5    8;    1    4    7];\r\nassert(isequal(rotateBy90(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":4,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":937,"test_suite_updated_at":"2016-10-23T02:03:04.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-02-25T21:37:41.000Z","updated_at":"2026-03-16T18:52:05.000Z","published_at":"2012-02-25T21:41:25.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\u003eCovering some basic topics I haven't seen elsewhere on Cody.\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\u003eRotate the input matrix 90 degrees counterclockwise (e.g. [1 2; 3 4] -\u003e [2 4; 1 3]\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":44624,"title":"Return median of a matrix","description":"Compute median of a matrix of any dimension. Exclude the NaNs if any.","description_html":"\u003cp\u003eCompute median of a matrix of any dimension. Exclude the NaNs if any.\u003c/p\u003e","function_template":"function y = matrix_median(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [2,3,4;4,5,6];\r\ny_correct = 4;\r\nassert(isequal(matrix_median(x),y_correct))\r\n\r\n%%\r\nx = int8(1:4);\r\ny_correct = 3;\r\nassert(isequal(matrix_median(x),y_correct))\r\n\r\n%%\r\nx = [2 6 8 10 NaN 14 NaN 18 NaN];\r\ny_correct = 9;\r\nassert(isequal(matrix_median(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-04-21T04:30:24.000Z","updated_at":"2026-02-18T11:12:59.000Z","published_at":"2018-04-21T04:30:24.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\u003eCompute median of a matrix of any dimension. Exclude the NaNs if any.\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":45502,"title":"Basic Operation with the middle number of odd matrix","description":"# Take an odd matrix *like* 3-by-3\r\n# Access the *middle element* of the matrix i.e in case of 3-by-3 matrix the index of the particular element is second row, second column.\r\n# Now, *sum* the elements in its column to it and then *subtract* the elements in its row to it.\r\n# What's the matrix with updated element.","description_html":"\u003col\u003e\u003cli\u003eTake an odd matrix \u003cb\u003elike\u003c/b\u003e 3-by-3\u003c/li\u003e\u003cli\u003eAccess the \u003cb\u003emiddle element\u003c/b\u003e of the matrix i.e in case of 3-by-3 matrix the index of the particular element is second row, second column.\u003c/li\u003e\u003cli\u003eNow, \u003cb\u003esum\u003c/b\u003e the elements in its column to it and then \u003cb\u003esubtract\u003c/b\u003e the elements in its row to it.\u003c/li\u003e\u003cli\u003eWhat's the matrix with updated element.\u003c/li\u003e\u003c/ol\u003e","function_template":"function y = your_fcn_name(A)\r\n% A is square matrix with odd rows and column or a row vector or a column vector\r\n%Write your code here\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 10; 7 8 9];\r\ny_correct = [1     2     3; 4     1    10; 7     8     9];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny_correct = [1     2    -9     4     5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1; 2; 3; 4; 5];\r\ny_correct = [1; 2; 15; 4; 5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":26467,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":"2020-05-09T17:11:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-07T19:17:59.000Z","updated_at":"2025-07-06T19:41:21.000Z","published_at":"2020-05-08T18:14: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\",\"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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTake an odd matrix\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\u003elike\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 3-by-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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAccess the\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\u003emiddle element\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the matrix i.e in case of 3-by-3 matrix the index of the particular element is second row, second column.\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\u003eNow,\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\u003esum\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the elements in its column to it and then\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\u003esubtract\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the elements in its row to it.\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\u003eWhat's the matrix with updated element.\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":1671,"title":"Generate the Matrix!","description":"Given n, generate the following matrix:\r\n\r\n  a = [ n  n-1 n-2 ... 2 1;\r\n       n-1 n-1 n-2 ... 2 1;\r\n       n-2 n-2 n-2 ... 2 1;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        2   2   2  ... 2 1;\r\n        1   1   1  ... 1 1]\r\n\r\nGood luck!","description_html":"\u003cp\u003eGiven n, generate the following matrix:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea = [ n  n-1 n-2 ... 2 1;\r\n     n-1 n-1 n-2 ... 2 1;\r\n     n-2 n-2 n-2 ... 2 1;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      2   2   2  ... 2 1;\r\n      1   1   1  ... 1 1]\r\n\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = mat_fun(n)\r\n  y = ones(n);\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 2;\r\ny_correct = [2 1; 1 1];\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = [3 2 1; 2 2 1; 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 4;\r\ny_correct = [4 3 2 1; 3 3 2 1; 2 2 2 1; 1 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":14930,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-21T17:16:38.000Z","updated_at":"2026-03-11T08:53:15.000Z","published_at":"2013-06-21T17:23:38.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, generate the following matrix:\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[a = [ n  n-1 n-2 ... 2 1;\\n     n-1 n-1 n-2 ... 2 1;\\n     n-2 n-2 n-2 ... 2 1;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      2   2   2  ... 2 1;\\n      1   1   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\u003eGood 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":44842,"title":"Double the next!","description":"Given two numbers, m and n, find a matrix [m,n] where each element value is twice the value of the previous element. Starting from the position (1,1) with value equal to 1, until the position (m,n), following the direction from left to right and from top to bottom.\r\nFor example, for m=2 and n=3, you should get:\r\ny = [1 2 4; 8 16 32].","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 123.438px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 332px 61.7188px; transform-origin: 332px 61.7188px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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: 309px 31.5px; text-align: left; transform-origin: 309px 31.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two numbers, m and n, find a matrix \u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; \"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003em,n\u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; \"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e where each element value is twice the value of the previous element. Starting from the position (1,1) with value equal to 1, until the position (m,n), following the direction from left to right and from top to bottom.\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: 309px 10.5px; text-align: left; transform-origin: 309px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, for m=2 and n=3, you should get:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4375px; 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: 329px 10.2188px; transform-origin: 329px 10.2188px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); 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; text-wrap: 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ey = [1 2 4; 8 16 32].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(m,n)\r\n  y = [];\r\nend","test_suite":"%%\r\nm = 3;\r\nn = 2; \r\ny_correct = [1 2; 4 8; 16 32];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 1;\r\nn = 1; \r\ny_correct = [1];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 1;\r\nn = 5; \r\ny_correct = [1 2 4 8 16];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 3;\r\nn = 1; \r\ny_correct = [1; 2; 4];\r\nassert(isequal(your_fcn_name(m,n),y_correct))\r\n\r\n%%\r\nm = 4;\r\nn = 2; \r\ny_correct = [1 2; 4 8; 16 32; 64 128];\r\nassert(isequal(your_fcn_name(m,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":274816,"edited_by":274816,"edited_at":"2024-07-03T13:09:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":54,"test_suite_updated_at":"2019-03-23T22:36:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-01-29T11:50:39.000Z","updated_at":"2026-03-04T14:52:41.000Z","published_at":"2019-01-29T11:50:39.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\u003eGiven two numbers, m and n, find a matrix [m,n] where each element value is twice the value of the previous element. Starting from the position (1,1) with value equal to 1, until the position (m,n), following the direction from left to right and from top to bottom.\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 m=2 and n=3, you should get:\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 = [1 2 4; 8 16 32].]]\u003e\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":44973,"title":"Create a \"+\" flag","description":"Given two odd numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0. \r\n\r\nFor example, [m, n] = [3, 3] would return\r\n\r\n  [0, 1, 0; \r\n   1, 1, 1; \r\n   0, 1, 0]\r\n\r\nIf either m or n is even, there is no row of ones (for m) or no column of ones (for n). So [m, n] = [4, 3] would return\r\n\r\n  [0, 1, 0; \r\n   0, 1, 0; \r\n   0, 1, 0; \r\n   0, 1, 0]\r\n\r\n[m, n] =[4, 4] would return \r\n\r\n  [0, 0, 0, 0; \r\n   0, 0, 0, 0;\r\n   0, 0, 0, 0; \r\n   0, 0, 0, 0]","description_html":"\u003cp\u003eGiven two odd numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\u003c/p\u003e\u003cp\u003eFor example, [m, n] = [3, 3] would return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[0, 1, 0; \r\n 1, 1, 1; \r\n 0, 1, 0]\r\n\u003c/pre\u003e\u003cp\u003eIf either m or n is even, there is no row of ones (for m) or no column of ones (for n). So [m, n] = [4, 3] would return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[0, 1, 0; \r\n 0, 1, 0; \r\n 0, 1, 0; \r\n 0, 1, 0]\r\n\u003c/pre\u003e\u003cp\u003e[m, n] =[4, 4] would return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[0, 0, 0, 0; \r\n 0, 0, 0, 0;\r\n 0, 0, 0, 0; \r\n 0, 0, 0, 0]\r\n\u003c/pre\u003e","function_template":"function y = crossFlag(m, n)\r\n  y = zeros(m,n);\r\nend","test_suite":"%%\r\nm = 3; n = 3;\r\ny_correct = [0, 1, 0; 1, 1, 1; 0, 1, 0];\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 5; n = 3;\r\ny_correct = [0, 1, 0; 0, 1, 0; 1, 1, 1; 0, 1, 0; 0, 1, 0];\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 16; n = 8;\r\ny_correct = zeros(16,8);\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 7; n = 280;\r\ny_correct = [zeros(3,280); ones(1,280); zeros(3,280)];\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 1; n = 1;\r\ny_correct = 1;\r\nassert(isequal(crossFlag(m, n),y_correct))\r\n\r\n%%\r\nm = 7; n = 13;\r\ny_correct =[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0;...\r\n    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0];\r\nassert(isequal(crossFlag(m, n),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":157354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":"2019-10-09T18:25:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-03T11:15:19.000Z","updated_at":"2026-03-24T11:58:02.000Z","published_at":"2019-10-03T11:15: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\u003eGiven two odd numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\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, [m, n] = [3, 3] would return\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, 0; \\n 1, 1, 1; \\n 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\u003eIf either m or n is even, there is no row of ones (for m) or no column of ones (for n). So [m, n] = [4, 3] would return\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, 0; \\n 0, 1, 0; \\n 0, 1, 0; \\n 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\u003e[m, n] =[4, 4] would return\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, 0, 0, 0; \\n 0, 0, 0, 0;\\n 0, 0, 0, 0; \\n 0, 0, 0, 0]]]\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":44635,"title":"Repetition of matrices","description":"*A is a bold matrix: [1 2 3; 4 5 6;7 8 9]*\r\n\r\nGiven an integer 'n' , a matrix B exists such that has n copies of A in the row and column dimensions\r\n\r\nexample:\r\nfor n=2; B= [A A; A A]\r\n\r\nFor such a matrix B return the sum of all elements multiplied by the size of B i.e. \r\n\r\n  C=sum (all elements of B) * size(B)\r\n\r\n* _Kindly note you will have to make the matrix A yourself_ *","description_html":"\u003cp\u003e\u003cb\u003eA is a bold matrix: [1 2 3; 4 5 6;7 8 9]\u003c/b\u003e\u003c/p\u003e\u003cp\u003eGiven an integer 'n' , a matrix B exists such that has n copies of A in the row and column dimensions\u003c/p\u003e\u003cp\u003eexample:\r\nfor n=2; B= [A A; A A]\u003c/p\u003e\u003cp\u003eFor such a matrix B return the sum of all elements multiplied by the size of B i.e.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eC=sum (all elements of B) * size(B)\r\n\u003c/pre\u003e\u003cul\u003e\u003cli\u003e\u003ci\u003eKindly note you will have to make the matrix A yourself\u003c/i\u003e *\u003c/li\u003e\u003c/ul\u003e","function_template":"function C = matrix_rep(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nn = 2;\r\nC_correct = [1080,1080];\r\nassert(isequal(matrix_rep(n),C_correct))\r\n\r\n%%\r\nn = 5;\r\nC_correct = [16875,16875];\r\nassert(isequal(matrix_rep(n),C_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":"2018-05-09T11:43:47.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T11:42:39.000Z","updated_at":"2026-03-05T11:04:40.000Z","published_at":"2018-05-09T11:42: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA is a bold matrix: [1 2 3; 4 5 6;7 8 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\u003eGiven an integer 'n' , a matrix B exists such that has n copies of A in the row and column dimensions\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 n=2; B= [A A; A A]\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 such a matrix B return the sum of all elements multiplied by the size of B i.e.\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[C=sum (all elements of B) * size(B)]]\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eKindly note you will have to make the matrix A yourself\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\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":42456,"title":"Create an array (n,n) where only diagonal elements are '1' and others are '0'","description":"Create an array (n,n) where only diagonal elements are '1' and others are '0'\r\n\r\nEX: n = 3;\r\nthen Resultant array would be [ 1 0 1\r\n\r\n                                0 1 0\r\n\r\n                                1 0 1 ]                                 ","description_html":"\u003cp\u003eCreate an array (n,n) where only diagonal elements are '1' and others are '0'\u003c/p\u003e\u003cp\u003eEX: n = 3;\r\nthen Resultant array would be [ 1 0 1\u003c/p\u003e\u003cpre\u003e                                0 1 0\u003c/pre\u003e\u003cpre\u003e                                1 0 1 ]                                 \u003c/pre\u003e","function_template":"function y = getArrayWithDiagOnes(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(getArrayWithDiagOnes(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = [1,1;1,1];\r\nassert(isequal(getArrayWithDiagOnes(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [1 0 0 0 1;0 1 0 1 0;0 0 1 0 0;0 1 0 1 0;1 0 0 0 1];\r\nassert(isequal(getArrayWithDiagOnes(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46593,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-07-09T06:27:11.000Z","updated_at":"2026-02-18T15:40:46.000Z","published_at":"2015-07-09T06:29:00.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\u003eCreate an array (n,n) where only diagonal elements are '1' and others are '0'\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\u003eEX: n = 3; then Resultant array would be [ 1 0 1\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 0\\n\\n                                1 0 1 ]]]\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":44665,"title":"Percentage of zeros in a matrix of only 1s and 0s","description":"Write a function called _zero_stat_ that takes a matrix as an input that only has 0 and 1 elements. The function needs to compute and return the percentage of 0 elements in the matrix. For example, if there are 10 zeros and 15 ones in a 5-by-5 matrix that is provided as an input to zero_stat, it would return 40 because 40% of the elements are zero.\r\n*Please return the answer rounded to the nearest integer*","description_html":"\u003cp\u003eWrite a function called \u003ci\u003ezero_stat\u003c/i\u003e that takes a matrix as an input that only has 0 and 1 elements. The function needs to compute and return the percentage of 0 elements in the matrix. For example, if there are 10 zeros and 15 ones in a 5-by-5 matrix that is provided as an input to zero_stat, it would return 40 because 40% of the elements are zero. \u003cb\u003ePlease return the answer rounded to the nearest integer\u003c/b\u003e\u003c/p\u003e","function_template":"function pct_zero = zero_stat(inp_matrix)\r\nend","test_suite":"%%\r\ninp_matrix = [1,0,0,1,1;0,1,1,0,0;0,0,0,0,0;1,1,1,1,1;1,1,1,1,1];\r\npct_zero_corr = 40;\r\nassert(isequal(zero_stat(inp_matrix),pct_zero_corr))\r\n\r\n%%\r\ninp_matrix = diag([1,0,1,1,1]);\r\npct_zero_corr = 84;\r\nassert(isequal(zero_stat(inp_matrix),pct_zero_corr))\r\n\r\n%%\r\ninp_matrix = [1,0,1,0,0,0,1]';\r\npct_zero_corr = 57;\r\nassert(isequal(zero_stat(inp_matrix),pct_zero_corr))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-29T15:29:49.000Z","updated_at":"2026-04-02T10:26:58.000Z","published_at":"2018-05-29T15:29:49.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\u003eWrite a function called\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\u003ezero_stat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that takes a matrix as an input that only has 0 and 1 elements. The function needs to compute and return the percentage of 0 elements in the matrix. For example, if there are 10 zeros and 15 ones in a 5-by-5 matrix that is provided as an input to zero_stat, it would return 40 because 40% of the elements are zero.\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\u003ePlease return the answer rounded to the nearest integer\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":42457,"title":"Get the array of sum for three consecutive numbers in an array","description":"Get the array of sum, for three consecutive numbers in an array.\r\n\r\nif Input 'x' does not have at-least 3 elements then 'y' should be zero. \r\n\r\nEX:- x = [1,2,3,4] then y = [6,9]\r\n\r\n   x = [4,9,2,6,1,7] then y = [15,17,9,14]\r\n  \r\n   x = 1 then y = 0;\r\n\r\n\r\n","description_html":"\u003cp\u003eGet the array of sum, for three consecutive numbers in an array.\u003c/p\u003e\u003cp\u003eif Input 'x' does not have at-least 3 elements then 'y' should be zero.\u003c/p\u003e\u003cp\u003eEX:- x = [1,2,3,4] then y = [6,9]\u003c/p\u003e\u003cpre\u003e   x = [4,9,2,6,1,7] then y = [15,17,9,14]\u003c/pre\u003e\u003cpre\u003e   x = 1 then y = 0;\u003c/pre\u003e","function_template":"function y = GetSumOf3Numbers(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [15,17];\r\ny_correct = 0;\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\nx = [1];\r\ny_correct = 0;\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\n\r\nx = [1,2,3];\r\ny_correct = 6;\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\n\r\nx = [4,9,2,6,1,7];\r\ny_correct = [15,17,9,14];\r\nassert(isequal(GetSumOf3Numbers(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46593,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-07-09T09:25:12.000Z","updated_at":"2025-08-30T13:37:09.000Z","published_at":"2015-07-09T09:25:12.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\u003eGet the array of sum, for three consecutive numbers in an array.\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\u003eif Input 'x' does not have at-least 3 elements then 'y' should be zero.\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\u003eEX:- x = [1,2,3,4] then y = [6,9]\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 = [4,9,2,6,1,7] then y = [15,17,9,14]\\n\\n   x = 1 then y = 0;]]\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":43122,"title":"Upper Matrix Mock","description":"Given a vector v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:\r\n\r\nm=[1 3 6 9 11;\r\n   0 1 3 6 9;\r\n   0 0 1 3 6;\r\n   0 0 0 1 3;\r\n   0 0 0 0 1]","description_html":"\u003cp\u003eGiven a vector v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:\u003c/p\u003e\u003cp\u003em=[1 3 6 9 11;\r\n   0 1 3 6 9;\r\n   0 0 1 3 6;\r\n   0 0 0 1 3;\r\n   0 0 0 0 1]\u003c/p\u003e","function_template":"function y = upMatMock(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 3 6 9 11];\r\ny_correct = [1 3 6 9 11;\r\n   0 1 3 6 9;\r\n   0 0 1 3 6;\r\n   0 0 0 1 3;\r\n   0 0 0 0 1]\r\nassert(isequal(upMatMock(x),y_correct))\r\n%%\r\nx = [7 8 9 11];\r\ny_correct = [7 8 9 11;\r\n   0 7 8 9;\r\n   0 0 7 8;\r\n   0 0 0 7]\r\nassert(isequal(upMatMock(x),y_correct))","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":13865,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":"2016-10-29T17:02:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-06T10:26:31.000Z","updated_at":"2026-03-16T10:56:25.000Z","published_at":"2016-10-06T10:25:53.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 vector v=[1 3 6 9 11], turn it into a matrix 'ramp' like so:\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 3 6 9 11; 0 1 3 6 9; 0 0 1 3 6; 0 0 0 1 3; 0 0 0 0 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":44402,"title":"Horizontal matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 9  2  8  1\r\n      5  4  9  8\r\n      8  9  6  9\r\n  \r\n  y = 1  2  8  9  9  8  2  1\r\n      4  5  8  9  9  8  5  4\r\n      6  8  9  9  9  9  8  6","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 9  2  8  1\r\n    5  4  9  8\r\n    8  9  6  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 1  2  8  9  9  8  2  1\r\n    4  5  8  9  9  8  5  4\r\n    6  8  9  9  9  9  8  6\r\n\u003c/pre\u003e","function_template":"function y = backAndforth(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0 0];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = zeros(100);\r\nx(41,68) = 1;\r\ny_correct = zeros(100,200);\r\ny_correct(41,100:101) = [1,1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 2 3 4 4 3 2 1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x,fliplr(x)];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x,x];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1; 4; 3; 2];\r\ny_correct = [1 1; 4 4; 3 3; 2 2];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [9  2  8  1; 5  4  9  8; 8  9  6  9];\r\ny_correct = [1  2  8  9  9  8  2  1;\r\n             4  5  8  9  9  8  5  4;\r\n             6  8  9  9  9  9  8  6];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nr = [1:3:7,7:-3:1];\r\ny_correct = [r;r+1;r+2];\r\nassert(isequal(backAndforth(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":"2018-01-02T21:54:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-12T07:54:27.000Z","updated_at":"2026-03-29T20:13:01.000Z","published_at":"2017-11-12T07:59: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\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\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:\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 = 9  2  8  1\\n    5  4  9  8\\n    8  9  6  9\\n\\ny = 1  2  8  9  9  8  2  1\\n    4  5  8  9  9  8  5  4\\n    6  8  9  9  9  9  8  6]]\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":1812,"title":"Tridiagonal","description":"Return an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\r\n\r\nExample \r\n\r\n a=1\r\n b=2\r\n c=3\r\n n=5\r\n T =  [2     3     0     0     0;\r\n       1     2     3     0     0;\r\n       0     1     2     3     0;\r\n       0     0     1     2     3;\r\n       0     0     0     1     2]\r\n","description_html":"\u003cp\u003eReturn an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e a=1\r\n b=2\r\n c=3\r\n n=5\r\n T =  [2     3     0     0     0;\r\n       1     2     3     0     0;\r\n       0     1     2     3     0;\r\n       0     0     1     2     3;\r\n       0     0     0     1     2]\u003c/pre\u003e","function_template":"function T = tridiag(a, b, c, n)\r\n  \r\nend","test_suite":"%%\r\na = 1;\r\nb = 2;\r\nc = 3;\r\nn = 5;\r\ny_correct = [ 2     3     0     0     0;\r\n              1     2     3     0     0;\r\n              0     1     2     3     0;\r\n              0     0     1     2     3;\r\n              0     0     0     1     2];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 9;\r\nb = 5;\r\nc = -17;\r\nn = 3;\r\ny_correct = [ 5   -17     0 ;\r\n              9     5   -17 ;\r\n              0     9     5 ];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 4;\r\nb = -1;\r\nc = 8;\r\nn = 4;\r\ny_correct = [-1     8     0     0;\r\n              4    -1     8     0;\r\n              0     4    -1     8;\r\n              0     0     4    -1];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 11;\r\nb = 21;\r\nc = 30;\r\nn = 5;\r\ny_correct = [21    30     0     0     0;\r\n             11    21    30     0     0;\r\n              0    11    21    30     0;\r\n              0     0    11    21    30;\r\n              0     0     0    11    21];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":14639,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":173,"test_suite_updated_at":"2017-03-15T16:29:22.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-08-14T09:35:02.000Z","updated_at":"2026-02-27T15:40:54.000Z","published_at":"2013-08-14T09:35:02.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\u003eReturn an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in 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\u003eExample\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[ a=1\\n b=2\\n c=3\\n n=5\\n T =  [2     3     0     0     0;\\n       1     2     3     0     0;\\n       0     1     2     3     0;\\n       0     0     1     2     3;\\n       0     0     0     1     2]]]\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":44496,"title":"vector indexes for a matrix","description":"Matlab allows us to use several indexing styles making code simpler and easier to read than using loops. \r\n\r\nVectors can have vector subscripts\r\n\r\n  V = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n     2     4     6\r\n\r\nIn case of matrices, it allows us to use linear indexing.\r\n \r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n     2     4     6\r\n\r\n\r\nGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops. \r\n\r\nFor example (tl;dr)\r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\n  P = [1 1 2]; Q = [1 3 2];\r\n  Matrix_VectorIndexes(M,P,Q)\r\n  ans =\r\n     2     4     6\r\n\r\n","description_html":"\u003cp\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\u003c/p\u003e\u003cp\u003eVectors can have vector subscripts\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eV = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eIn case of matrices, it allows us to use linear indexing.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\u003c/p\u003e\u003cp\u003eFor example (tl;dr)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 1 2]; Q = [1 3 2];\r\nMatrix_VectorIndexes(M,P,Q)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e","function_template":"function y = Matrix_VectorIndexes(M,P,Q)\r\n  y = M(P,Q);  %M(P,Q) gives wrong answer because matlab reads it as linear indexing of matrices \r\n               % M(1,1) is not considered linear indexing, but M([1,1]),M([1],[1]) etc., is \r\nend","test_suite":"%%\r\nM = [1 2 3;\r\n     4 5 6;\r\n     7 8 9];\r\nP = [1 2 3]; Q= [1 2 3];\r\ny_correct = [1,5,9];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 3 2]; Q = [1 1 2];\r\ny_correct = [2,4,6];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = 1:3; Q = 3:-1:1;\r\ny_correct = [4,9,8];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = reshape(repmat((1:3)',[1,3]),[1,9]);\r\nQ = reshape(repmat(1:3,[3,1]),[1,9]);\r\ny_correct = M(:)';\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4 2;\r\n     7 9 6 1; \r\n     8 2 3 5];\r\nP = [2,1,3,2]; Q = 1:4;\r\ny_correct = [7,5,3,1];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":162999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2018-06-16T21:47:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-10T07:13:18.000Z","updated_at":"2026-04-02T13:18:07.000Z","published_at":"2018-01-10T07:33:32.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\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\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\u003eVectors can have vector subscripts\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[V = [2 3 4 5 6 7 8 9 10];\\nidx = [1 3 5];\\nV(idx)\\nans =\\n   2     4     6]]\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\u003eIn case of matrices, it allows us to use linear indexing.\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nidx = [1 3 5];\\nM(idx) \\nans =\\n   2     4     6]]\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\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\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 (tl;dr)\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nP = [1 1 2]; Q = [1 3 2];\\nMatrix_VectorIndexes(M,P,Q)\\nans =\\n   2     4     6]]\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":411,"title":"Back to basics 21 - Matrix replicating","description":"Covering some basic topics I haven't seen elsewhere on Cody.\r\n\r\nGiven an input matrix, generate an output matrix that consists of the input matrix replicated in a 2 by 2 pattern Examples:\r\n\r\n  [1] -\u003e [1 1\r\n          1 1]\r\n\r\n  [1 2       -\u003e [1 2 1 2\r\n   3 4]          3 4 3 4 \r\n                 1 2 1 2 \r\n                 3 4 3 4]","description_html":"\u003cp\u003eCovering some basic topics I haven't seen elsewhere on Cody.\u003c/p\u003e\u003cp\u003eGiven an input matrix, generate an output matrix that consists of the input matrix replicated in a 2 by 2 pattern Examples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[1] -\u003e [1 1\r\n        1 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e[1 2       -\u003e [1 2 1 2\r\n 3 4]          3 4 3 4 \r\n               1 2 1 2 \r\n               3 4 3 4]\r\n\u003c/pre\u003e","function_template":"function y = matrix_replication(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1];\r\ny_correct = [1 1;1 1];\r\nassert(isequal(matrix_replication(x),y_correct))\r\n\r\n%%\r\nx = [1 2;3 4];\r\ny_correct = [1 2 1 2; 3 4 3 4; 1 2 1 2; 3 4 3 4];\r\nassert(isequal(matrix_replication(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 2];\r\ny_correct = [1 2 1 2; 1 2 1 2];\r\nassert(isequal(matrix_replication(x),y_correct))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1798,"test_suite_updated_at":"2012-02-25T21:33:19.000Z","rescore_all_solutions":false,"group_id":19,"created_at":"2012-02-25T21:33:19.000Z","updated_at":"2026-03-28T23:57:05.000Z","published_at":"2012-02-25T21:33: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\u003eCovering some basic topics I haven't seen elsewhere on Cody.\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 an input matrix, generate an output matrix that consists of the input matrix replicated in a 2 by 2 pattern Examples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[1] -\u003e [1 1\\n        1 1]\\n\\n[1 2       -\u003e [1 2 1 2\\n 3 4]          3 4 3 4 \\n               1 2 1 2 \\n               3 4 3 4]]]\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":42646,"title":"Matrix FUN","description":"Given a Matrix M, find out the number of elements of matrix that are divisible by 3.\r\n\r\n  \r\n    M = [1 2 3;4 5 6;7 8 9];\r\n    out = 3\r\n\r\n    M = [32 12 15; 2 6 45];\r\n    out = 4\r\n ","description_html":"\u003cp\u003eGiven a Matrix M, find out the number of elements of matrix that are divisible by 3.\u003c/p\u003e\u003cpre\u003e    M = [1 2 3;4 5 6;7 8 9];\r\n    out = 3\u003c/pre\u003e\u003cpre\u003e    M = [32 12 15; 2 6 45];\r\n    out = 4\u003c/pre\u003e","function_template":"function y = mat_fun(m)\r\n  y = x; %think and solve\r\nend","test_suite":"%%\r\nx = 4;\r\ny_correct = 0;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [3 2 3 2 5 6 2 1 2];\r\ny_correct = 3;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [999 999 999 2 15 6];\r\ny_correct = 5;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = 3:3:999;\r\ny_correct = 333;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [1 2 3 4 5 6;6 5 4 3 2 1];\r\ny_correct = 4;\r\nassert(isequal(mat_fun(x),y_correct))\r\n%%\r\nx = [7 8 11 13 14 17];\r\ny_correct = 0;\r\nassert(isequal(mat_fun(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":44015,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":165,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-03T05:59:11.000Z","updated_at":"2026-03-23T15:33:33.000Z","published_at":"2015-10-03T06:00:26.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 Matrix M, find out the number of elements of matrix that are divisible by 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[    M = [1 2 3;4 5 6;7 8 9];\\n    out = 3\\n\\n    M = [32 12 15; 2 6 45];\\n    out = 4]]\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":54440,"title":"Create an arrow matrix","description":"An arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \r\n                                        \r\n                                        \r\n\r\nWrite a function that takes the number of rows and columns (for N \u003e= 3) as an input, and returns the corresponding arrow matrix.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 305px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 152.5px; transform-origin: 407px 152.5px; vertical-align: baseline; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 164px; 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 82px; text-align: left; transform-origin: 384px 82px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003cimg class=\"imageNode\" width=\"199\" height=\"158\" style=\"vertical-align: baseline;width: 199px;height: 158px\" src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAw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TI4IiB4PSIzOTYuMjg1IiB5PSI2MjgiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iNzkyLjU3IiB5PSI2MjgiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTE4OC44NSIgeT0iNjI4Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjYyOCI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIwIiB5PSI5NDYiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMzk2LjI4NSIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjExODguODUiIHk9Ijk0NiI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxNTg1LjE0IiB5PSI5NDYiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\" data-image-state=\"image-loaded\"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of rows and columns (for \u003c/span\u003e\u003c/span\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eN\u003c/span\u003e\u003c/span\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = arrow(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [1 0 1; 0 1 1; 1 1 1];\r\nassert(isequal(arrow(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = [1 0 0 0 0 1; 0 1 0 0 0 1; 0 0 1 0 0 1; 0 0 0 1 0 1; 0 0 0 0 1 1; 1 1 1 1 1 1];\r\nassert(isequal(arrow(x),y_correct))","published":true,"deleted":false,"likes_count":11,"comments_count":1,"created_by":571375,"edited_by":571375,"edited_at":"2022-10-03T14:11:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":560,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-05-03T17:40:18.000Z","updated_at":"2026-03-20T13:55:48.000Z","published_at":"2022-10-03T14:11:46.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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\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\u003e                                        \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"158\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"199\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes the number of rows and columns (for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.svg+xml\",\"relationshipId\":\"rId1\"}]},{\"partUri\":\"/media/image1.svg+xml\",\"contentType\":\"image/svg+xml\",\"content\":\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC05NDYgLTMzMCkiPjxwYXRoIGQ9Ik05NDguMzQ5IDMzMy4yMDQgMTM0NC42MyAzMzMuMjA0IDEzNDQuNjMgNjM3LjU1IDk0OC4zNDkgNjM3LjU1WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTEzNDQuNjMgMzMzLjIwNCAxNzQwLjkyIDMzMy4yMDQgMTc0MC45MiA2MzcuNTUgMTM0NC42MyA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzMuMjA0IDIxMzcuMiAzMzMuMjA0IDIxMzcuMiA2MzcuNTUgMTc0MC45MiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5v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IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":43073,"title":"Check if a matrix is a palindrome in all directions","description":"Check if a matrix is a palindrome both vertically and horizontally.\r\n\r\nYou function will return *true* for |[1,2,1]| or |[2,7,2; 6,9,6; 2,7,2]| . But it should return *false* for |[1,2,3]| or |[2,7,2; 6,9,6; 3,5,3]| .","description_html":"\u003cp\u003eCheck if a matrix is a palindrome both vertically and horizontally.\u003c/p\u003e\u003cp\u003eYou function will return \u003cb\u003etrue\u003c/b\u003e for \u003ctt\u003e[1,2,1]\u003c/tt\u003e or \u003ctt\u003e[2,7,2; 6,9,6; 2,7,2]\u003c/tt\u003e . But it should return \u003cb\u003efalse\u003c/b\u003e for \u003ctt\u003e[1,2,3]\u003c/tt\u003e or \u003ctt\u003e[2,7,2; 6,9,6; 3,5,3]\u003c/tt\u003e .\u003c/p\u003e","function_template":"function y = isPalindrome(x)\r\n    y = true;\r\nend","test_suite":"%%\r\nx = [4,5,5,4];\r\ny_correct = true;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx =ones(4);\r\ny_correct = true;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx = [2,7,2; 6,9,6; 2,7,2];\r\ny_correct = true;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx = [1,2,3];\r\ny_correct = false;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n\r\n%%\r\nx = [2,7,2; 6,9,6; 3,5,3];\r\ny_correct = false;\r\nassert(isequal(isPalindrome(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":25354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":135,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2016-10-05T20:25:20.000Z","updated_at":"2026-03-12T16:10:38.000Z","published_at":"2016-10-05T20:25:20.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\u003eCheck if a matrix is a palindrome both vertically and horizontally.\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 function will return\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\u003etrue\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[1,2,1]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2,7,2; 6,9,6; 2,7,2]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e . But it should return\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\u003efalse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[1,2,3]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2,7,2; 6,9,6; 3,5,3]\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\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":44854,"title":"Alternating 1´s and 0´s in a matrix","description":"Given an odd number n, write a function that creates a matrix y with dimension nxn alternating 1's and 0's, and starting with 1 in the center of the matrix. For example, for n=3 one should get:\r\n\r\n  y = [0 0 0 ; 0 1 0; 0 0 0]\r\n","description_html":"\u003cp\u003eGiven an odd number n, write a function that creates a matrix y with dimension nxn alternating 1's and 0's, and starting with 1 in the center of the matrix. For example, for n=3 one should get:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ey = [0 0 0 ; 0 1 0; 0 0 0]\r\n\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [0 0 0; 0 1 0; 0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [1 1 1 1 1; 1 0 0 0 1; 1 0 1 0 1; 1 0 0 0 1; 1 1 1 1 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 7;\r\ny_correct = [0 0 0 0 0 0 0; 0 1 1 1 1 1 0; 0 1 0 0 0 1 0; 0 1 0 1 0 1 0; 0 1 0 0 0 1 0; 0 1 1 1 1 1 0; 0 0 0 0 0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":274816,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-02-18T17:53:18.000Z","updated_at":"2025-12-31T12:22:19.000Z","published_at":"2019-02-18T17:53:18.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 an odd number n, write a function that creates a matrix y with dimension nxn alternating 1's and 0's, and starting with 1 in the center of the matrix. For example, for n=3 one should get:\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 ; 0 1 0; 0 0 0]]]\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":2290,"title":"チェッカーボードを作ろう","description":"整数 n が与えられた時、以下の様な1と0を含むn×nの行列を作成しましょう。a(1,1) は1にする必要があります。\r\n\r\n例：\r\n\r\n 入力  n = 5\r\n 出力 a が [1 0 1 0 1\r\n              0 1 0 1 0\r\n              1 0 1 0 1\r\n              0 1 0 1 0 \r\n              1 0 1 0 1]\r\n\r\n* (英語版) Problem 4. Make a checkerboard matrix\r\n\u003chttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003e","description_html":"\u003cp\u003e整数 n が与えられた時、以下の様な1と0を含むn×nの行列を作成しましょう。a(1,1) は1にする必要があります。\u003c/p\u003e\u003cp\u003e例：\u003c/p\u003e\u003cpre\u003e 入力  n = 5\r\n 出力 a が [1 0 1 0 1\r\n              0 1 0 1 0\r\n              1 0 1 0 1\r\n              0 1 0 1 0 \r\n              1 0 1 0 1]\u003c/pre\u003e\u003cul\u003e\u003cli\u003e(英語版) Problem 4. Make a checkerboard matrix \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function a = checkerboard(x)\r\n  a = ones(n);\r\nend","test_suite":"%%\r\nn = 5;\r\na = [1 0 1 0 1;\r\n     0 1 0 1 0;\r\n     1 0 1 0 1;\r\n     0 1 0 1 0;\r\n     1 0 1 0 1];\r\nassert(isequal(a,checkerboard(n)))\r\n\r\n%%\r\nn = 4;\r\na = [1 0 1 0;\r\n     0 1 0 1;\r\n     1 0 1 0;\r\n     0 1 0 1];\r\nassert(isequal(a,checkerboard(n)))","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":11824,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":400,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":36,"created_at":"2014-04-18T01:33:12.000Z","updated_at":"2026-03-16T19:04:58.000Z","published_at":"2014-04-18T01:33:17.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\u003e整数 n が与えられた時、以下の様な1と0を含むn×nの行列を作成しましょう。a(1,1) は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\u003e例：\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[ 入力  n = 5\\n 出力 a が [1 0 1 0 1\\n              0 1 0 1 0\\n              1 0 1 0 1\\n              0 1 0 1 0 \\n              1 0 1 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=\\\"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(英語版) Problem 4. Make a checkerboard matrix\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/4-make-a-checkerboard-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":44446,"title":"Add a vector to a matrix","description":"Given a matrix |mat| of size |mXn| and a row vector |v| of size |1Xs|, return a matrix with |m+1| rows that conatains |mat| over |v|.\r\nThe number of columns is the larger between |n| and |s|.\r\n\r\nIf |s\u003en|, the matrix is padded with |Inf|.\r\n\r\nIf |n\u003es|, the vector is padded with |-Inf|.\r\n\r\nExamples:\r\n\r\n  inputs:\r\n  mat = [1  2\r\n         3  4]\r\n  v   = [5  6  7  8]\r\n\r\n  output:\r\n  comb = [1   2   Inf  Inf\r\n          3   4   Inf  Inf\r\n          5   6   7    8  ]\r\n\r\n  inputs:\r\n  mat = [1   2   3   4   5\r\n         6   7   8   9   10]\r\n  v   = [11  12]\r\n\r\n  output:\r\n  comb = [1    2     3     4     5\r\n          6    7     8     9     10\r\n          11   12   -Inf  -Inf  -Inf]","description_html":"\u003cp\u003eGiven a matrix \u003ctt\u003emat\u003c/tt\u003e of size \u003ctt\u003emXn\u003c/tt\u003e and a row vector \u003ctt\u003ev\u003c/tt\u003e of size \u003ctt\u003e1Xs\u003c/tt\u003e, return a matrix with \u003ctt\u003em+1\u003c/tt\u003e rows that conatains \u003ctt\u003emat\u003c/tt\u003e over \u003ctt\u003ev\u003c/tt\u003e.\r\nThe number of columns is the larger between \u003ctt\u003en\u003c/tt\u003e and \u003ctt\u003es\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003es\u0026gt;n\u003c/tt\u003e, the matrix is padded with \u003ctt\u003eInf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003en\u0026gt;s\u003c/tt\u003e, the vector is padded with \u003ctt\u003e-Inf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1  2\r\n       3  4]\r\nv   = [5  6  7  8]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1   2   Inf  Inf\r\n        3   4   Inf  Inf\r\n        5   6   7    8  ]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1   2   3   4   5\r\n       6   7   8   9   10]\r\nv   = [11  12]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1    2     3     4     5\r\n        6    7     8     9     10\r\n        11   12   -Inf  -Inf  -Inf]\r\n\u003c/pre\u003e","function_template":"function comb = addVecToMat(mat, v)\r\n  comb = [mat; v];\r\nend","test_suite":"%%\r\nfiletext = fileread('addVecToMat.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nmat = ones(2);\r\nv   = 1:3;\r\ncomb_correct = [1 1 inf; 1 1 inf; 1 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3, 4);\r\nv   = [2 3];\r\ncomb_correct = [ones(3,4); 2 3 -inf -inf];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(2);\r\nv   = [2 3];\r\ncomb_correct = [1 1; 1 1; 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3);\r\nv   = 1:6;\r\ncomb_correct = [repmat([ones(1,3) inf(1,3)], 3, 1); 1:6];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":186,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-11T00:10:48.000Z","updated_at":"2025-11-29T16:14:21.000Z","published_at":"2017-12-11T00:10: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\",\"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 matrix\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a row vector\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1Xs\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return a matrix 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em+1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e rows that conatains\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e over\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The number of columns is the larger between\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:rFonts w:cs=\\\"monospace\\\"/\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u0026gt;n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the matrix is padded 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInf\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u0026gt;s\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the vector is padded 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e-Inf\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\u003eExamples:\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[inputs:\\nmat = [1  2\\n       3  4]\\nv   = [5  6  7  8]\\n\\noutput:\\ncomb = [1   2   Inf  Inf\\n        3   4   Inf  Inf\\n        5   6   7    8  ]\\n\\ninputs:\\nmat = [1   2   3   4   5\\n       6   7   8   9   10]\\nv   = [11  12]\\n\\noutput:\\ncomb = [1    2     3     4     5\\n        6    7     8     9     10\\n        11   12   -Inf  -Inf  -Inf]]]\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":413,"title":"Back to basics 23 - Triangular matrix","description":"Covering some basic topics I haven't seen elsewhere on Cody.\r\n\r\nGiven an input matrix, return a matrix with all elements above and to the right of the main diagonal set to zero. Example:\r\n\r\n  input = [ 1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]\r\n  output = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1]\r\n","description_html":"\u003cp\u003eCovering some basic topics I haven't seen elsewhere on Cody.\u003c/p\u003e\u003cp\u003eGiven an input matrix, return a matrix with all elements above and to the right of the main diagonal set to zero. Example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput = [ 1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]\r\noutput = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1]\r\n\u003c/pre\u003e","function_template":"function y = triangle(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = ones(4,4);\r\ny_correct = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1];\r\nassert(isequal(triangle(x),y_correct))\r\n\r\n%%\r\nx = ones(5,5);\r\ny_correct = [1 0 0 0 0; 1 1 0 0 0; 1 1 1 0 0; 1 1 1 1 0; 1 1 1 1 1];\r\nassert(isequal(triangle(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:16,[4,4]);\r\ny_correct = [1 2 3 4; 0 6 7 8; 0 0 11 12; 0 0 0 16]';\r\nassert(isequal(triangle(x),y_correct))\r\n\r\n%%\r\nx = [0 1 2 3; 0 0 1 2; 0 0 0 1; 0 0 0 0];\r\ny_correct = zeros(4);\r\nassert(isequal(triangle(x),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":3,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1122,"test_suite_updated_at":"2017-02-24T16:49:14.000Z","rescore_all_solutions":false,"group_id":19,"created_at":"2012-02-25T21:46:25.000Z","updated_at":"2026-03-15T18:45:01.000Z","published_at":"2012-02-25T21:46:25.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\u003eCovering some basic topics I haven't seen elsewhere on Cody.\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 an input matrix, return a matrix with all elements above and to the right of the main diagonal set to zero. 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[input = [ 1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]\\noutput = [1 0 0 0; 1 1 0 0; 1 1 1 0; 1 1 1 1]]]\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":45172,"title":"Cross (\"+\") flag returns","description":"Given two numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\r\nGiven two even numbers, [p, q], return a matrix of size p x q which has the centre band of two numbers set as 1. However, there must be at least four zeros on the outer corners of the matrix.\r\nFor example, [m, n] = [3, 3] would return:\r\n[0,1,0;\r\n1,1,1;\r\n0,1,0];\r\nAnd for even numbers: [p, q] = [4, 3] would return\r\n[0,1,0;\r\n1,1,1;\r\n1,1,1;\r\n0,1,0];","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: 317.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 158.517px; transform-origin: 407px 158.517px; vertical-align: baseline; \"\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: 383px 8px; transform-origin: 383px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 279.5px 8px; transform-origin: 279.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two even numbers, [p, q], return a matrix of size p x q which has the centre band of\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003etwo\u003c/span\u003e\u003c/span\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: 90px 8px; transform-origin: 90px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e numbers set as 1. However, there must be at least four zeros on the outer corners 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: 127.5px 8px; transform-origin: 127.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, [m, n] = [3, 3] would return:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; 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 30.65px; transform-origin: 404px 30.65px; 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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[0,1,0;\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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1,1,1;\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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e0,1,0];\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: 155px 8px; transform-origin: 155px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAnd for even numbers: [p, q] = [4, 3] would return\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 404px 40.8667px; 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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[0,1,0;\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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1,1,1;\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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e1,1,1;\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: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e0,1,0];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = crossFlag2(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nm = 2; n = 2;\r\ny_correct = zeros(2,2);\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 3; n = 3;\r\ny_correct = [0, 1, 0; 1, 1, 1; 0, 1, 0];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 4; n = 4;\r\ny_correct = [0,1,1,0;\r\n             1,1,1,1;\r\n             1,1,1,1;\r\n             0,1,1,0];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 5; n = 3;\r\ny_correct = [0, 1, 0; 0, 1, 0; 1, 1, 1; 0, 1, 0; 0, 1, 0];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 3; n = 1;\r\ny_correct = ones(m,n);\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 16; n = 8;\r\ny_correct = [zeros(7,3),ones(7,2),zeros(7,3);ones(2,8);zeros(7,3),ones(7,2),zeros(7,3)];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 7; n = 280;\r\ny_correct = [zeros(3,139), ones(3,2), zeros(3,139); ones(1,280); zeros(3,139), ones(3,2), zeros(3,139)];\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 1; n = 1;\r\ny_correct = 1;\r\nassert(isequal(crossFlag2(m, n),y_correct))\r\n\r\n%%\r\nm = 0; n = 0;\r\ny_correct =[];\r\nassert(isequal(crossFlag2(m, n),y_correct));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":8,"created_by":157354,"edited_by":223089,"edited_at":"2022-11-25T07:01:15.000Z","deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2022-11-25T07:01:15.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-11T20:16:53.000Z","updated_at":"2026-03-11T12:00:48.000Z","published_at":"2019-10-11T20:16:53.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eGiven two numbers, [m, n], return a matrix of size m x n which has all elements of the centre column and centre row set as 1, and all other elements in the matrix set as 0.\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\u003eGiven two even numbers, [p, q], return a matrix of size p x q which has the centre band 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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003etwo\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e numbers set as 1. However, there must be at least four zeros on the outer corners 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, [m, n] = [3, 3] would return:\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,0;\\n1,1,1;\\n0,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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnd for even numbers: [p, q] = [4, 3] would return\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,0;\\n1,1,1;\\n1,1,1;\\n0,1,0];]]\u003e\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":44063,"title":"Make a rainbow matrix (follow-up to checkerboard matrix)","description":"Given an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.\r\n\r\nThis is a follow-up question to Cody Challenge CheckerBoard Problem at \u003chttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003e\r\n\r\nFor n=10 \r\n\r\n Input  n = 10\r\n Output a is\r\n  [0   1   2   3   4   5   6   7   8   9\r\n   1   2   3   4   5   6   7   8   9   8\r\n   2   3   4   5   6   7   8   9   8   7\r\n   3   4   5   6   7   8   9   8   7   6\r\n   4   5   6   7   8   9   8   7   6   5\r\n   5   6   7   8   9   8   7   6   5   4\r\n   6   7   8   9   8   7   6   5   4   3\r\n   7   8   9   8   7   6   5   4   3   2\r\n   8   9   8   7   6   5   4   3   2   1\r\n   9   8   7   6   5   4   3   2   1   0]\r\n   ","description_html":"\u003cp\u003eGiven an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.\u003c/p\u003e\u003cp\u003eThis is a follow-up question to Cody Challenge CheckerBoard Problem at \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/a\u003e\u003c/p\u003e\u003cp\u003eFor n=10\u003c/p\u003e\u003cpre\u003e Input  n = 10\r\n Output a is\r\n  [0   1   2   3   4   5   6   7   8   9\r\n   1   2   3   4   5   6   7   8   9   8\r\n   2   3   4   5   6   7   8   9   8   7\r\n   3   4   5   6   7   8   9   8   7   6\r\n   4   5   6   7   8   9   8   7   6   5\r\n   5   6   7   8   9   8   7   6   5   4\r\n   6   7   8   9   8   7   6   5   4   3\r\n   7   8   9   8   7   6   5   4   3   2\r\n   8   9   8   7   6   5   4   3   2   1\r\n   9   8   7   6   5   4   3   2   1   0]\u003c/pre\u003e","function_template":"function a = rainBowMatrix(n)\r\n  a = magic(n);\r\nend","test_suite":"%%\r\nn = 2;\r\na_correct = [0 1;\r\n             1 0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 3;\r\na_correct = [0 1 2;\r\n             1 2 1;\r\n             2 1 0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 4;\r\na_correct = [0   1   2   3;\r\n             1   2   3   2;\r\n             2   3   2   1;\r\n             3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 5;\r\na_correct = [0   1   2   3   4;\r\n             1   2   3   4   3;\r\n             2   3   4   3   2;\r\n             3   4   3   2   1;\r\n             4   3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 6;\r\na_correct = [0   1   2   3   4   5;\r\n             1   2   3   4   5   4;\r\n             2   3   4   5   4   3;\r\n             3   4   5   4   3   2;\r\n             4   5   4   3   2   1;\r\n             5   4   3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n%%\r\nn = 8;\r\na_correct = [0   1   2   3   4   5   6   7;\r\n             1   2   3   4   5   6   7   6;\r\n             2   3   4   5   6   7   6   5;\r\n             3   4   5   6   7   6   5   4;\r\n             4   5   6   7   6   5   4   3;\r\n             5   6   7   6   5   4   3   2;\r\n             6   7   6   5   4   3   2   1;\r\n             7   6   5   4   3   2   1   0];\r\nassert(isequal(rainBowMatrix(n),a_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":115733,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2018-07-31T17:49:51.000Z","rescore_all_solutions":false,"group_id":41,"created_at":"2017-02-09T18:42:50.000Z","updated_at":"2026-02-27T13:38:30.000Z","published_at":"2017-02-09T18:50:34.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 an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.\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\u003eThis is a follow-up question to Cody Challenge CheckerBoard Problem at\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/4-make-a-checkerboard-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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 n=10\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[ Input  n = 10\\n Output a is\\n  [0   1   2   3   4   5   6   7   8   9\\n   1   2   3   4   5   6   7   8   9   8\\n   2   3   4   5   6   7   8   9   8   7\\n   3   4   5   6   7   8   9   8   7   6\\n   4   5   6   7   8   9   8   7   6   5\\n   5   6   7   8   9   8   7   6   5   4\\n   6   7   8   9   8   7   6   5   4   3\\n   7   8   9   8   7   6   5   4   3   2\\n   8   9   8   7   6   5   4   3   2   1\\n   9   8   7   6   5   4   3   2   1   0]]]\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":2254,"title":"Possible Opponents Matrix for single-elimination tournament","description":"It's tournament time!\r\n\r\nGiven a single-elimination tournament with 2^N competitors, compute the 2^N by 2^N matrix M such that M(i,j)=1 iff competitor i might play competitor j in round R, where 1\u003c=R\u003c=N.  (In each round each surviving competitor plays his \"next door neighbor\" in the bracket.)\r\n\r\nFor example, if N=1, R=1 then\r\n\r\n M =\r\n   [ 0 1\r\n     1 0]\r\n\r\nor if N=2, R=2 then\r\n\r\n M = \r\n   [ 0 0 1 1 \r\n     0 0 1 1\r\n     1 1 0 0 \r\n     1 1 0 0 ]","description_html":"\u003cp\u003eIt's tournament time!\u003c/p\u003e\u003cp\u003eGiven a single-elimination tournament with 2^N competitors, compute the 2^N by 2^N matrix M such that M(i,j)=1 iff competitor i might play competitor j in round R, where 1\u0026lt;=R\u0026lt;=N.  (In each round each surviving competitor plays his \"next door neighbor\" in the bracket.)\u003c/p\u003e\u003cp\u003eFor example, if N=1, R=1 then\u003c/p\u003e\u003cpre\u003e M =\r\n   [ 0 1\r\n     1 0]\u003c/pre\u003e\u003cp\u003eor if N=2, R=2 then\u003c/p\u003e\u003cpre\u003e M = \r\n   [ 0 0 1 1 \r\n     0 0 1 1\r\n     1 1 0 0 \r\n     1 1 0 0 ]\u003c/pre\u003e","function_template":"function [ o ] = opponents( N , R )\r\n  o=zeros(2^N);\r\nend","test_suite":"1\r\n%%\r\no=opponents(1,1);\r\nassert(isequal(o,[0 1;1 0]))\r\n2\r\n%%\r\no=opponents(2,1);\r\nassert(isequal(o,[0 1 0 0;1 0 0 0;0 0 0 1;0 0 1 0]))\r\n3\r\n%%\r\no=opponents(2,2);\r\nassert(isequal(o,[0 0 1 1;0 0 1 1;1 1 0 0 ;1 1 0 0]))\r\n4\r\n%%\r\nfor w=1:5\r\n    N=randi(5);\r\n    R=randi(N);\r\n    o=opponents(N,R);\r\n    assert(isequal(size(o),[2^N 2^N]))\r\n    for v=1:10;\r\n        i=randi(2^N);\r\n        j=randi(2^N);\r\n        q=dec2bin([i;j]-1,N)-'0';\r\n        % i might face j in round R if they are identical\r\n        % in the leftmost N-R bits, but differ in the (N-R+1)th bit\r\n        assert(o(i,j)==(1==polyval(abs(diff(q(:,1:N-R+1))),2)))\r\n    end\r\nend\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":6,"created_by":4567,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":11,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-23T17:48:43.000Z","updated_at":"2014-03-24T18:14:20.000Z","published_at":"2014-03-23T17:48:43.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\u003eIt's tournament time!\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 single-elimination tournament with 2^N competitors, compute the 2^N by 2^N matrix M such that M(i,j)=1 iff competitor i might play competitor j in round R, where 1\u0026lt;=R\u0026lt;=N. (In each round each surviving competitor plays his \\\"next door neighbor\\\" in the bracket.)\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 N=1, R=1 then\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[ M =\\n   [ 0 1\\n     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\u003eor if N=2, R=2 then\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[ M = \\n   [ 0 0 1 1 \\n     0 0 1 1\\n     1 1 0 0 \\n     1 1 0 0 ]]]\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":44468,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":163,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T22:09:37.000Z","updated_at":"2026-03-11T17:00:04.000Z","published_at":"2017-12-24T22:09:37.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 a positive integer\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty 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\u003eExamples:\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[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\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":312,"title":"Better bullseye matrix","description":"\u003chttp://www.mathworks.com/matlabcentral/cody/problems/18-bullseye-matrix Problem 18\u003e asks to create a bullseye matrix like this:\r\n\r\n  [ 3 3 3 3 3\r\n    3 2 2 2 3 \r\n    3 2 1 2 3\r\n    3 2 2 2 3 \r\n    3 3 3 3 3 ] \r\n\r\nBut I think a better one would look like this:\r\n\r\n  [ 5 4 3 4 5\r\n    4 3 2 3 4\r\n    3 2 1 2 3\r\n    4 3 2 3 4\r\n    5 4 3 4 5 ]\r\n\r\nThus given n (always odd), return output a that has concentric rings of the numbers 1 through n around the center point. \r\n","description_html":"\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/18-bullseye-matrix\"\u003eProblem 18\u003c/a\u003e asks to create a bullseye matrix like this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[ 3 3 3 3 3\r\n  3 2 2 2 3 \r\n  3 2 1 2 3\r\n  3 2 2 2 3 \r\n  3 3 3 3 3 ] \r\n\u003c/pre\u003e\u003cp\u003eBut I think a better one would look like this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[ 5 4 3 4 5\r\n  4 3 2 3 4\r\n  3 2 1 2 3\r\n  4 3 2 3 4\r\n  5 4 3 4 5 ]\r\n\u003c/pre\u003e\u003cp\u003eThus given n (always odd), return output a that has concentric rings of the numbers 1 through n around the center point.\u003c/p\u003e","function_template":"function a = bullseye(n)\r\n  a = zeros(n);\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(bullseye(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = [3 2 3; 2 1 2; 3 2 3];\r\nassert(isequal(bullseye(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [5     4     3     4     5; 4     3     2     3     4; 3     2     1     2     3; 4     3     2     3     4;     5     4     3     4     5];\r\nassert(isequal(bullseye(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":1022,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":249,"test_suite_updated_at":"2012-02-12T06:44:11.000Z","rescore_all_solutions":false,"group_id":18,"created_at":"2012-02-12T06:44:11.000Z","updated_at":"2026-02-10T21:45:27.000Z","published_at":"2012-02-12T06:44: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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/18-bullseye-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 18\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asks to create a bullseye matrix like this:\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[[ 3 3 3 3 3\\n  3 2 2 2 3 \\n  3 2 1 2 3\\n  3 2 2 2 3 \\n  3 3 3 3 3 ]]]\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\u003eBut I think a better one would look like this:\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[[ 5 4 3 4 5\\n  4 3 2 3 4\\n  3 2 1 2 3\\n  4 3 2 3 4\\n  5 4 3 4 5 ]]]\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\u003eThus given n (always odd), return output a that has concentric rings of the numbers 1 through n around the center point.\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":45171,"title":"Squares in Squares - Concentric Squares","description":"Given a number, n, create an n x n sized matrix with concentric squares of 1s from the outside in. There should be a gap between each square (represented by 0s). \r\n\r\nIf n is even, the centre of the matrix should be a 2 x 2 square of 0s or 1s, if it is odd it should be a 1 x 1 square. \r\n\r\nThe function should return the square matrix, S, and the number of squares, Sn, (in some cases this may only be one).\r\n\r\n  e.g. n = 7\r\n    1 1 1 1 1 1 1\r\n    1 0 0 0 0 0 1\r\n    1 0 1 1 1 0 1\r\n    1 0 1 0 1 0 1\r\n    1 0 1 1 1 0 1\r\n    1 0 0 0 0 0 1\r\n    1 1 1 1 1 1 1\r\n\r\n\r\n","description_html":"\u003cp\u003eGiven a number, n, create an n x n sized matrix with concentric squares of 1s from the outside in. There should be a gap between each square (represented by 0s).\u003c/p\u003e\u003cp\u003eIf n is even, the centre of the matrix should be a 2 x 2 square of 0s or 1s, if it is odd it should be a 1 x 1 square.\u003c/p\u003e\u003cp\u003eThe function should return the square matrix, S, and the number of squares, Sn, (in some cases this may only be one).\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ee.g. n = 7\r\n  1 1 1 1 1 1 1\r\n  1 0 0 0 0 0 1\r\n  1 0 1 1 1 0 1\r\n  1 0 1 0 1 0 1\r\n  1 0 1 1 1 0 1\r\n  1 0 0 0 0 0 1\r\n  1 1 1 1 1 1 1\r\n\u003c/pre\u003e","function_template":"function [S,Sn] = squaresinsquares(n)\r\n  S = ones(n);\r\nend","test_suite":"%%\r\nn = 7;\r\nS_correct = ...\r\n   [1 1 1 1 1 1 1;\r\n    1 0 0 0 0 0 1;\r\n    1 0 1 1 1 0 1;\r\n    1 0 1 0 1 0 1;\r\n    1 0 1 1 1 0 1;\r\n    1 0 0 0 0 0 1;\r\n    1 1 1 1 1 1 1];\r\nSn_correct = 2;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 2;\r\nS_correct = [1 1; 1 1];\r\nSn_correct = 1;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 1;\r\nS_correct = 1;\r\nSn_correct = 1;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 10;\r\nSn_correct = 3;\r\n[~,Sn] = squaresinsquares(n);\r\nassert(isequal(Sn,Sn_correct));\r\n\r\n%%\r\nn = 6;\r\nS_correct = ...\r\n   [1 1 1 1 1 1;\r\n    1 0 0 0 0 1;\r\n    1 0 1 1 0 1;\r\n    1 0 1 1 0 1;\r\n    1 0 0 0 0 1;\r\n    1 1 1 1 1 1];\r\nSn_correct = 2;\r\n[S,Sn] = squaresinsquares(n);\r\nassert(isequal(S,S_correct));\r\nassert(isequal(Sn,Sn_correct));","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":162339,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-11T10:40:01.000Z","updated_at":"2019-10-11T10:40:01.000Z","published_at":"2019-10-11T10:40:01.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 number, n, create an n x n sized matrix with concentric squares of 1s from the outside in. There should be a gap between each square (represented by 0s).\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\u003eIf n is even, the centre of the matrix should be a 2 x 2 square of 0s or 1s, if it is odd it should be a 1 x 1 square.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe function should return the square matrix, S, and the number of squares, Sn, (in some cases this may only be one).\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[e.g. n = 7\\n  1 1 1 1 1 1 1\\n  1 0 0 0 0 0 1\\n  1 0 1 1 1 0 1\\n  1 0 1 0 1 0 1\\n  1 0 1 1 1 0 1\\n  1 0 0 0 0 0 1\\n  1 1 1 1 1 1 1]]\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":611,"title":"surrounded matrix","description":"With a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:\r\n\r\n  A = [1 2 3\r\n       3 2 1]\r\n  \r\n  B = [1 1 1 1 1\r\n       1 1 2 3 1\r\n       1 3 2 1 1\r\n       1 1 1 1 1]\r\n\r\nor\r\n\r\n  A = 4\r\n\r\n  B = [ 1 1 1\r\n        1 4 1\r\n        1 1 1]","description_html":"\u003cp\u003eWith a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [1 2 3\r\n     3 2 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eB = [1 1 1 1 1\r\n     1 1 2 3 1\r\n     1 3 2 1 1\r\n     1 1 1 1 1]\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = 4\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eB = [ 1 1 1\r\n      1 4 1\r\n      1 1 1]\r\n\u003c/pre\u003e","function_template":"function B = surrounded(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = ones(3);\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = [3 3 3;3 3 3];\r\ny_correct = [1 1 1 1 1;1 3 3 3 1; 1 3 3 3 1; 1 1 1 1 1];\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = ones(3,4);\r\ny_correct = ones(5,6);\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = [0];\r\ny_correct = ones(3); y_correct(2,2) = 0;\r\nassert(isequal(surrounded(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\ny_correct = [1 1 1 1 1; 1 1 2 3 1; ...\r\n    1 4 5 6 1; 1 7 8 9 1; 1 1 1 1 1]';\r\nassert(isequal(surrounded(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":3062,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1453,"test_suite_updated_at":"2017-02-24T16:54:28.000Z","rescore_all_solutions":false,"group_id":19,"created_at":"2012-04-22T09:21:22.000Z","updated_at":"2026-04-02T19:15:31.000Z","published_at":"2012-04-22T09:24:58.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\u003eWith a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:\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[A = [1 2 3\\n     3 2 1]\\n\\nB = [1 1 1 1 1\\n     1 1 2 3 1\\n     1 3 2 1 1\\n     1 1 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\u003eor\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[A = 4\\n\\nB = [ 1 1 1\\n      1 4 1\\n      1 1 1]]]\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":2303,"title":"Compute Hamming distances between each pair of rows from two input matrices","description":"For two input matrices _u_ ( _n_ x _uCols_ ) and _v_ ( _n_ x _vCols_ ) of numbers in range [0..255] (8-bit), such that each column represents an  _(8 x n)_-dimensional binary vector, calculate _uCols_ x _vCols_ matrix with each entry _(i,j)_ being a Hamming distance between _i_ -th and _j_ -th column from inputs _u_ and _v_ respectively.\r\n","description_html":"\u003cp\u003eFor two input matrices \u003ci\u003eu\u003c/i\u003e ( \u003ci\u003en\u003c/i\u003e x \u003ci\u003euCols\u003c/i\u003e ) and \u003ci\u003ev\u003c/i\u003e ( \u003ci\u003en\u003c/i\u003e x \u003ci\u003evCols\u003c/i\u003e ) of numbers in range [0..255] (8-bit), such that each column represents an  \u003ci\u003e(8 x n)\u003c/i\u003e-dimensional binary vector, calculate \u003ci\u003euCols\u003c/i\u003e x \u003ci\u003evCols\u003c/i\u003e matrix with each entry \u003ci\u003e(i,j)\u003c/i\u003e being a Hamming distance between \u003ci\u003ei\u003c/i\u003e -th and \u003ci\u003ej\u003c/i\u003e -th column from inputs \u003ci\u003eu\u003c/i\u003e and \u003ci\u003ev\u003c/i\u003e respectively.\u003c/p\u003e","function_template":"function y = hammings(u, v)\r\n  y = zeros(size(u,2),size(v,2));\r\nend","test_suite":"%% test 0\r\nq  = [0 \r\n      0];\r\ndb = [0 0\r\n      0 0];\r\nhamming_distances = [0 0];\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n\r\n%% test 1\r\nq  = 128;\r\ndb = 4;\r\nhamming_distances = 2;\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n\r\n\r\n%% test 2\r\nq  = [  0   0 0 \r\n      128 128 0];\r\ndb = [128 255 0\r\n        0   0 0];\r\nhamming_distances = [2 9 1; 2 9 1; 1 8 0];\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n\r\n\r\n%% test 3\r\nq  = [128  \r\n      128];\r\ndb = [255 0\r\n      255 0];\r\nhamming_distances = [14 2];\r\nassert(isequal(hammings(q, db), hamming_distances));\r\n\r\n\r\n%% test 4\r\nq  = [  0   0 0 \r\n      128 128 0];\r\ndb = [128 255\r\n        0   0];\r\nhamming_distances = [2 9; 2 9; 1 8];\r\nassert(isequal(hammings(q, db), hamming_distances ));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":6084,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-01T17:29:58.000Z","updated_at":"2014-05-01T17:42:00.000Z","published_at":"2014-05-01T17:42:00.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 two input matrices\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\u003eu\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 x\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\u003euCols\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\u003ev\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 x\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\u003evCols\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) of numbers in range [0..255] (8-bit), such that each column represents an \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\u003e(8 x n)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-dimensional binary vector, calculate\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\u003euCols\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e x\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\u003evCols\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix with each entry\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\u003e(i,j)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e being a Hamming distance between\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\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e -th 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\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e -th column from 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\u003eu\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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e respectively.\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":58822,"title":"Make a \"better\" checkerboard matrix","description":"This problem seeks to expand the task in Cody Problem 4 by allowing for the creation of checkerboard matrices that can be rectangular and have squares of 0s and 1s that are larger than a single element, 1x1 (i.e. 2x2, 3x3, etc).\r\nThe result is a rectangular checkerboard where the scale of the squares relative to the board can be manipulated.\r\nFor this problem, the given values are height (h), width (w), and size of squares (n), and the first square should be 1s.\r\nExample:\r\nh = 6\r\nw = 4\r\nn = 2\r\nsolution = \r\n            1     1     0     0\r\n            1     1     0     0\r\n            0     0     1     1\r\n            0     0     1     1\r\n            1     1     0     0\r\n            1     1     0     0\r\nNote, it is possible for there to be conflicts between the dimensions of the checkerboard and the size of the squares. For example, the size of the squares must be smaller than both the height and width dimensions (n\u003cheight \u0026\u0026 n\u003cwidth). There are other possibilities for dimensional conflicts as well. For the sake of this problem, the test suite values/dimensions will be agreeable; in the future, there will be another problem for handling the challenge of disagreeable dimensions.\r\n\r\n*** This exercise has applications for image manipulation as the resulting checkerboard matrix can be used for image operations like masking and filtering. The height and width values translate to the pixel height and width of an image and square size (n) can be interpreted as a block or grain size. Another reintepretation of this problem in comparison to the simpler checkerboard matrix problem is that the solution to this problem produces checkerboard matrices of variable resolution.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 584.375px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 292.188px; transform-origin: 407.5px 292.188px; vertical-align: baseline; \"\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: 384.5px 21px; text-align: left; transform-origin: 384.5px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis problem seeks to expand the task in \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCody Problem 4\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e by allowing for the creation of checkerboard matrices that can be rectangular and have squares of 0s and 1s that are larger than a single element, 1x1 (i.e. 2x2, 3x3, etc).\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe result is a rectangular checkerboard where the scale of the squares relative to the board can be manipulated.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFor this problem, the given values are height (h), width (w), and size of squares (n), and the first square should be 1s.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 204.375px; 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: 404.5px 102.188px; transform-origin: 404.5px 102.188px; 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.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eh = 6\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ew = 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003en = 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003esolution = \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            0     0     1     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            0     0     1     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            1     1     0     0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 84px; 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: 384.5px 42px; text-align: left; transform-origin: 384.5px 42px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eNote, it is possible for there to be conflicts between the dimensions of the checkerboard and the size of the squares. For example, the size of the squares must be smaller than both the height and width dimensions (n\u0026lt;height \u0026amp;\u0026amp; n\u0026lt;width). There are other possibilities for dimensional conflicts as well. For the sake of this problem, the test suite values/dimensions will be agreeable; in the future, there will be another problem for handling the challenge of disagreeable dimensions.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 105px; 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: 384.5px 52.5px; text-align: left; transform-origin: 384.5px 52.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e*** This exercise has applications for image manipulation as the resulting checkerboard matrix can be used for image operations like masking and filtering. The height and width values translate to the pixel height and width of an image and square size (n) can be interpreted as a block or grain size. Another reintepretation of this problem in comparison to the simpler checkerboard matrix problem is that the solution to this problem produces checkerboard matrices of variable resolution.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function output = checkermatrix(h,w,n)\r\noutput = zeros(h,w);\r\n\r\nend\r\n\r\n        ","test_suite":"%%\r\nfiletext = fileread('checkermatrix.m');\r\nassert(isempty(strfind(filetext, 'checkerboard')),'checkerboard() forbidden')\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp() forbidden')\r\nassert(isempty(strfind(filetext, 'regexprep')),'regexprep() forbidden')\r\n\r\n%%\r\nh = 3;\r\nw = 3;\r\nn = 1;\r\nsolution = [1 0 1; 0 1 0; 1 0 1];\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 10;\r\nw = 10;\r\nn = 2;\r\nsolution = [1     1     0     0     1     1     0     0     1     1;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            0     0     1     1     0     0     1     1     0     0;\r\n            1     1     0     0     1     1     0     0     1     1;\r\n            1     1     0     0     1     1     0     0     1     1];\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 10;\r\nw = 10;\r\nn = 10;\r\nsolution = ones(n);\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 6;\r\nw = 4;\r\nn = 2;\r\nsolution = [1     1     0     0;\r\n            1     1     0     0;\r\n            0     0     1     1;\r\n            0     0     1     1;\r\n            1     1     0     0;\r\n            1     1     0     0];\r\nassert(isequal(checkermatrix(h,w,n),solution))\r\n\r\n%%\r\nh = 6;\r\nw = 3;\r\nn = 3;\r\nsolution = [1     1     1;\r\n            1     1     1;\r\n            1     1     1;\r\n            0     0     0;\r\n            0     0     0;\r\n            0     0     0];\r\nassert(isequal(checkermatrix(h,w,n),solution))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":3499438,"edited_by":3499438,"edited_at":"2023-11-05T07:19:37.000Z","deleted_by":null,"deleted_at":null,"solvers_count":11,"test_suite_updated_at":"2023-08-10T18:28:02.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-08-07T19:53:06.000Z","updated_at":"2023-11-05T07:19:37.000Z","published_at":"2023-08-07T19:57:02.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eThis problem seeks to expand the task in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Problem 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e by allowing for the creation of checkerboard matrices that can be rectangular and have squares of 0s and 1s that are larger than a single element, 1x1 (i.e. 2x2, 3x3, etc).\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 result is a rectangular checkerboard where the scale of the squares relative to the board can be manipulated.\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 this problem, the given values are height (h), width (w), and size of squares (n), and the first square should be 1s.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[h = 6\\nw = 4\\nn = 2\\nsolution = \\n            1     1     0     0\\n            1     1     0     0\\n            0     0     1     1\\n            0     0     1     1\\n            1     1     0     0\\n            1     1     0     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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote, it is possible for there to be conflicts between the dimensions of the checkerboard and the size of the squares. For example, the size of the squares must be smaller than both the height and width dimensions (n\u0026lt;height \u0026amp;\u0026amp; n\u0026lt;width). There are other possibilities for dimensional conflicts as well. For the sake of this problem, the test suite values/dimensions will be agreeable; in the future, there will be another problem for handling the challenge of disagreeable dimensions.\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\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\u003e*** This exercise has applications for image manipulation as the resulting checkerboard matrix can be used for image operations like masking and filtering. The height and width values translate to the pixel height and width of an image and square size (n) can be interpreted as a block or grain size. Another reintepretation of this problem in comparison to the simpler checkerboard matrix problem is that the solution to this problem produces checkerboard matrices of variable resolution.\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":44469,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":482,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2017-12-24T22:09:41.000Z","updated_at":"2026-02-14T08:55:51.000Z","published_at":"2017-12-24T22:09:41.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 a positive integer\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\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\u003eIf\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty 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\u003eExamples:\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[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\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\"}]}"}],"term":"tag:\"matrices\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"matrices\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"matrices\"","","\"","matrices","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f2515b13848\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f2515b137a8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f2515b12ee8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f2515b13ac8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f2515b13a28\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f2515b13988\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f2515b138e8\u003e":"tag:\"matrices\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f2515b138e8\u003e":"tag:\"matrices\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"matrices\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"matrices\"","","\"","matrices","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f2515b13848\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f2515b137a8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f2515b12ee8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f2515b13ac8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f2515b13a28\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f2515b13988\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f2515b138e8\u003e":"tag:\"matrices\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f2515b138e8\u003e":"tag:\"matrices\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":60686,"difficulty_rating":"easy"},{"id":44634,"difficulty_rating":"easy"},{"id":44546,"difficulty_rating":"easy"},{"id":59244,"difficulty_rating":"easy"},{"id":42346,"difficulty_rating":"easy"},{"id":44401,"difficulty_rating":"easy"},{"id":43272,"difficulty_rating":"easy"},{"id":44613,"difficulty_rating":"easy"},{"id":44687,"difficulty_rating":"easy"},{"id":44740,"difficulty_rating":"easy"},{"id":1926,"difficulty_rating":"easy"},{"id":46105,"difficulty_rating":"easy"},{"id":44447,"difficulty_rating":"easy"},{"id":1171,"difficulty_rating":"easy"},{"id":61296,"difficulty_rating":"easy"},{"id":44671,"difficulty_rating":"easy"},{"id":2350,"difficulty_rating":"easy"},{"id":45173,"difficulty_rating":"easy"},{"id":412,"difficulty_rating":"easy"},{"id":44624,"difficulty_rating":"easy"},{"id":45502,"difficulty_rating":"easy"},{"id":1671,"difficulty_rating":"easy"},{"id":44842,"difficulty_rating":"easy"},{"id":44973,"difficulty_rating":"easy"},{"id":44635,"difficulty_rating":"easy"},{"id":42456,"difficulty_rating":"easy"},{"id":44665,"difficulty_rating":"easy"},{"id":42457,"difficulty_rating":"easy"},{"id":43122,"difficulty_rating":"easy"},{"id":44402,"difficulty_rating":"easy-medium"},{"id":1812,"difficulty_rating":"easy-medium"},{"id":44496,"difficulty_rating":"easy-medium"},{"id":411,"difficulty_rating":"easy-medium"},{"id":42646,"difficulty_rating":"easy-medium"},{"id":54440,"difficulty_rating":"easy-medium"},{"id":43073,"difficulty_rating":"easy-medium"},{"id":44854,"difficulty_rating":"easy-medium"},{"id":2290,"difficulty_rating":"easy-medium"},{"id":44446,"difficulty_rating":"easy-medium"},{"id":413,"difficulty_rating":"easy-medium"},{"id":45172,"difficulty_rating":"easy-medium"},{"id":44063,"difficulty_rating":"easy-medium"},{"id":2254,"difficulty_rating":"easy-medium"},{"id":44468,"difficulty_rating":"easy-medium"},{"id":312,"difficulty_rating":"easy-medium"},{"id":45171,"difficulty_rating":"easy-medium"},{"id":611,"difficulty_rating":"easy-medium"},{"id":2303,"difficulty_rating":"easy-medium"},{"id":58822,"difficulty_rating":"easy-medium"},{"id":44469,"difficulty_rating":"easy-medium"}]}}