{"group":{"group":{"id":64,"name":"Operations","lockable":false,"created_at":"2018-08-28T18:10:23.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"They say that the devil is in the details.","is_default":false,"created_by":26769,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":36,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":943,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: 21.9px; min-height: 0px; white-space: normal; color: rgb(64, 64, 64); font-family: Arial, Helvetica, sans-serif; font-style: normal; font-size: 15px; font-weight: 400; text-decoration: none solid rgb(64, 64, 64); white-space: normal; \"\u003e\u003cdiv style=\"\"\u003e\u003cdiv style=\"text-align: left; \"\u003e\u003cspan style=\"block-size: auto; display: inline; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2020-09-21T16:40:47.000Z"},"current_player":null},"problems":[{"id":2797,"title":"modular arithmetic","description":"Given three integers a,b and c, find the remainder when a^b is divided by c. Here, a^b will be well beyond the largest 64 bit integer.\r\n\r\nExample:\r\n\r\n  a = 1000\r\n  b = 1000\r\n  c = 3\r\n  \r\n  Answer = 1","description_html":"\u003cp\u003eGiven three integers a,b and c, find the remainder when a^b is divided by c. Here, a^b will be well beyond the largest 64 bit integer.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea = 1000\r\nb = 1000\r\nc = 3\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eAnswer = 1\r\n\u003c/pre\u003e","function_template":"function y = mod_exp(a,b,c)\r\n\r\n\r\n\r\nend","test_suite":"%%\r\nassert(isequal(mod_exp(1000,1000,3),1))\r\n\r\n%%\r\nassert(isequal(mod_exp(1444,2113,104),40))\r\n\r\n%%\r\nassert(isequal(mod_exp(1043,313,23),16))\r\n\r\n%%\r\nassert(isequal(mod_exp(1111,1111,111),1))\r\n\r\n%%\r\nassert(isequal(mod_exp(1531,9898,123),73))\r\n\r\n%%\r\nassert(isequal(mod_exp(1323,7878,12),9))\r\n\r\n%%\r\nassert(isequal(mod_exp(4545,1234,786),429))\r\n\r\n%%\r\na = [151:160];\r\nb = [311:320];\r\nc = [41:50];\r\nr = [35 22 38 0 35 16 8 16 40 0];\r\nid = randperm(10);\r\na = a(id);\r\nb = b(id);\r\nc = c(id);\r\nr = r(id);\r\nfor i = 1:10\r\n    assert(isequal(mod_exp(a(i),b(i),c(i)),r(i)))\r\nend","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-12-22T08:34:31.000Z","updated_at":"2026-04-03T02:37:46.000Z","published_at":"2014-12-22T08:34:31.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 three integers a,b and c, find the remainder when a^b is divided by c. Here, a^b will be well beyond the largest 64 bit integer.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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 = 1000\\nb = 1000\\nc = 3\\n\\nAnswer = 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":2240,"title":"Sum the 'edge' values of a matrix","description":"Sum the 'edge' values of an input matrix (the values along the perimeter).\r\n\r\nExample\r\n\r\n [1 2 3\r\n  4 5 6\r\n  7 8 9]\r\n\r\nOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\r\n\r\nAssumption: Input matrix equal or bigger than 3x3.","description_html":"\u003cp\u003eSum the 'edge' values of an input matrix (the values along the perimeter).\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e [1 2 3\r\n  4 5 6\r\n  7 8 9]\u003c/pre\u003e\u003cp\u003eOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\u003c/p\u003e\u003cp\u003eAssumption: Input matrix equal or bigger than 3x3.\u003c/p\u003e","function_template":"function y = AddMatrixLim(x)\r\n %add code\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6;7 8 9];\r\ny_correct = 40;\r\nassert(isequal(AddMatrixLim(x),y_correct))\r\n\r\n%%\r\nx= [1 5 6 7; 4 9 4 7; 9 4 2 1; 0 1 2 8]\r\ny_correct = 51;\r\nassert(isequal(AddMatrixLim(x),y_correct))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":24008,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":402,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-09T13:39:17.000Z","updated_at":"2026-04-03T02:38:49.000Z","published_at":"2014-03-09T13:39: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\u003eSum the 'edge' values of an input matrix (the values along the perimeter).\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[ [1 2 3\\n  4 5 6\\n  7 8 9]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput = 1 + 2 + 3 + 6 + 9 + 8 + 7 + 4 = 40;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssumption: Input matrix equal or bigger than 3x3.\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":43283,"title":"Subtract integers and add doubles","description":"Create a function that subtracts a from b if a and b are integers and adds them if they are floats.","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 10.5px; vertical-align: baseline; perspective-origin: 332px 10.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eCreate a function that subtracts b from a if a and b are integers and adds them if they are floats.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function c = intOrfloat(a, b)\r\n  if isinteger(a)\r\n      a = a + b;\r\n  else\r\n      a = a - b;\r\n  end\r\nend","test_suite":"%%\r\na = int8(1);\r\nb = int8(2);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,-1))\r\n\r\n%%\r\na = 1;\r\nb = 2;\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,3))\r\n\r\n%%\r\na = uint8(1);\r\nb = uint8(2);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,0))\r\n\r\n%%\r\na = int16(100);\r\nb = int16(200);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,-100))\r\n\r\n%%\r\na = single(100);\r\nb = single(200);\r\nc = intOrfloat(a, b)\r\nassert(isequal(c,300))","published":true,"deleted":false,"likes_count":4,"comments_count":4,"created_by":57323,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":130,"test_suite_updated_at":"2016-10-28T02:19:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-09T15:33:19.000Z","updated_at":"2026-04-03T02:39:22.000Z","published_at":"2016-10-09T15:33:19.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\u003eCreate a function that subtracts b from a if a and b are integers and adds them if they are floats.\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":2157,"title":"Multiplication","description":"Multiply two numbers in a different manner.\r\nThe numbers are given to you as vectors x and y.\r\n\r\nExample\r\n\r\n x = [ 1 2 0 1 ]\r\n\r\n y = [ 8 5 1 ]\r\n\r\n      1  2  0  1\r\n X       8  5  1\r\n-------------------\r\n      1  2  0  1\r\n   5 10  0  5\r\n8 16  0  8\r\n----------------\r\n8 21 11 10  5  1 \r\n\r\n","description_html":"\u003cp\u003eMultiply two numbers in a different manner.\r\nThe numbers are given to you as vectors x and y.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x = [ 1 2 0 1 ]\u003c/pre\u003e\u003cpre\u003e y = [ 8 5 1 ]\u003c/pre\u003e\u003cpre\u003e      1  2  0  1\r\n X       8  5  1\r\n-------------------\r\n      1  2  0  1\r\n   5 10  0  5\r\n8 16  0  8\r\n----------------\r\n8 21 11 10  5  1 \u003c/pre\u003e","function_template":"function result= muldif(x,y)\r\n  result = (x*y);\r\nend","test_suite":"%%\r\nx=[1 2];\r\ny=1;\r\ny_correct=[1 2];\r\nassert(isequal(muldif(x,y),y_correct));\r\n%%\r\nx=1;\r\ny=1;\r\ny_correct=1;\r\nassert(isequal(muldif(x,y),y_correct));\r\n%%\r\nx=[1 2 0 1];\r\ny=[8 5 1];\r\ny_correct = [8 21 11 10  5  1];\r\nassert(isequal(muldif(x,y),y_correct))\r\n%%\r\nx=[1 2 3 4 4 1 2 1 1 1];\r\ny=[1 2 3 4 5 6 9 10];\r\n y_correct=[1     4    10    20    34    49    68    90   104   109   101    73    43    40    25    19    10];\r\nassert(isequal(muldif(x,y),y_correct));\r\n%%\r\nx=[1:10 0 1];\r\ny=[8 5:1:25 1];\r\ny_correct = [8\t21\t40\t66\t100\t143\t196\t260\t336\t425\t440\t503\t555\t611\t667\t723\t779\t835\t891\t947\t1003\t1059\t1090\t1094\t1070\t1017\t934\t820\t674\t495\t282\t34\t25\t1\r\n];\r\nassert(isequal(muldif(x,y),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":3,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":113,"test_suite_updated_at":"2014-02-06T11:37:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-06T09:07:12.000Z","updated_at":"2026-04-03T03:17:32.000Z","published_at":"2014-02-06T09:07: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\u003eMultiply two numbers in a different manner. The numbers are given to you as vectors x and y.\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 = [ 1 2 0 1 ]\\n\\n y = [ 8 5 1 ]\\n\\n      1  2  0  1\\n X       8  5  1\\n-------------------\\n      1  2  0  1\\n   5 10  0  5\\n8 16  0  8\\n----------------\\n8 21 11 10  5  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":2161,"title":"Let's get back to school, and create multiplication tables","description":"For a given range, create multiplication tables. (start is always \u003c endno)\r\n\r\nExample\r\n\r\n start = 17\r\n endno = 19\r\n\r\nThen, \r\n\r\n table = \r\n  [ 17    18    19\r\n    34    36    38\r\n    51    54    57\r\n    68    72    76\r\n    85    90    95\r\n   102   108   114\r\n   119   126   133\r\n   136   144   152\r\n   153   162   171\r\n   170   180   190 ]\r\n","description_html":"\u003cp\u003eFor a given range, create multiplication tables. (start is always \u0026lt; endno)\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e start = 17\r\n endno = 19\u003c/pre\u003e\u003cp\u003eThen,\u003c/p\u003e\u003cpre\u003e table = \r\n  [ 17    18    19\r\n    34    36    38\r\n    51    54    57\r\n    68    72    76\r\n    85    90    95\r\n   102   108   114\r\n   119   126   133\r\n   136   144   152\r\n   153   162   171\r\n   170   180   190 ]\u003c/pre\u003e","function_template":"function table= Tables(start, endno)\r\n  table = [start:endno];\r\nend","test_suite":"%%\r\nstart = 1;\r\nendno = 10;\r\ny_correct = [1     2     3     4     5     6     7     8     9    10;\r\n     2     4     6     8    10    12    14    16    18    20;\r\n     3     6     9    12    15    18    21    24    27    30;\r\n     4     8    12    16    20    24    28    32    36    40;\r\n     5    10    15    20    25    30    35    40    45    50;\r\n     6    12    18    24    30    36    42    48    54    60;\r\n     7    14    21    28    35    42    49    56    63    70;\r\n     8    16    24    32    40    48    56    64    72    80;\r\n     9    18    27    36    45    54    63    72    81    90;\r\n    10    20    30    40    50    60    70    80    90   100;];\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n%%\r\nstart = 17;\r\nendno = 19;\r\ny_correct = [17    18    19;\r\n    34    36    38;\r\n    51    54    57;\r\n    68    72    76;\r\n    85    90    95;\r\n   102   108   114;\r\n   119   126   133;\r\n   136   144   152;\r\n   153   162   171;\r\n   170   180   190;];\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n%%\r\nstart = 21;\r\nendno = 22;\r\n\r\ny_correct =[21    22;\r\n    42    44;\r\n    63    66;\r\n    84    88;\r\n   105   110;\r\n   126   132;\r\n   147   154;\r\n   168   176;\r\n   189   198;\r\n   210   220;]\r\nassert(isequal(Tables(start, endno),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":240,"test_suite_updated_at":"2014-02-06T17:58:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-06T17:45:15.000Z","updated_at":"2026-04-03T02:41:10.000Z","published_at":"2014-02-06T17:49: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\u003eFor a given range, create multiplication tables. (start is always \u0026lt; endno)\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[ start = 17\\n endno = 19]]\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,\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[ table = \\n  [ 17    18    19\\n    34    36    38\\n    51    54    57\\n    68    72    76\\n    85    90    95\\n   102   108   114\\n   119   126   133\\n   136   144   152\\n   153   162   171\\n   170   180   190 ]]]\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":110,"title":"Make an N-dimensional Multiplication Table","description":"*INSTRUCTIONS*\r\n\r\nThis is a multi-dimensional variant of the normal multiplication table used to teach elementary students multiplication. In this variant, we are going to produce a table that multiplies the divisors 1 to _n_ (input) agains itself in _d_ dimensions.\r\n\r\n_Note_: Inputting _d_ = 0 should return the number 1 and _d_ = 1 should return a column vector with the elements 1 to _n_.\r\n\r\n\r\n*Example:*\r\n\r\nInput: \r\n\r\n  n = 3;\r\n  d = 3;\r\n\r\nOutput:\r\n\r\n  tt(:,:,1) = [ 1  2  3\r\n                2  4  6\r\n                3  6  9  ];\r\n  tt(:,:,2) = [ 2  4  6\r\n                4  8  12\r\n                6  12 18 ];\r\n  tt(:,:,3) = [ 3  6  9\r\n                6  12 18\r\n                9  18 27 ];","description_html":"\u003cp\u003e\u003cb\u003eINSTRUCTIONS\u003c/b\u003e\u003c/p\u003e\u003cp\u003eThis is a multi-dimensional variant of the normal multiplication table used to teach elementary students multiplication. In this variant, we are going to produce a table that multiplies the divisors 1 to \u003ci\u003en\u003c/i\u003e (input) agains itself in \u003ci\u003ed\u003c/i\u003e dimensions.\u003c/p\u003e\u003cp\u003e\u003ci\u003eNote\u003c/i\u003e: Inputting \u003ci\u003ed\u003c/i\u003e = 0 should return the number 1 and \u003ci\u003ed\u003c/i\u003e = 1 should return a column vector with the elements 1 to \u003ci\u003en\u003c/i\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eInput:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 3;\r\nd = 3;\r\n\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ett(:,:,1) = [ 1  2  3\r\n              2  4  6\r\n              3  6  9  ];\r\ntt(:,:,2) = [ 2  4  6\r\n              4  8  12\r\n              6  12 18 ];\r\ntt(:,:,3) = [ 3  6  9\r\n              6  12 18\r\n              9  18 27 ];\r\n\u003c/pre\u003e","function_template":"function tt = ndtimestable(n,d)\r\n  tt = zeros(n*ones(1,d));\r\nend","test_suite":"%%\r\nm = 5;\r\nn = 0;\r\ntt = 1;\r\nassert(isequal(ndtimestable(m,n),tt))\r\n\r\n%%\r\nm = 10;\r\nn = 1;\r\ntt = (1:10)';\r\nassert(isequal(ndtimestable(m,n),tt))\r\n\r\n%%\r\nm = 12;\r\nn = 2;\r\ntt= [    1     2     3     4     5     6     7     8     9    10    11    12\r\n         2     4     6     8    10    12    14    16    18    20    22    24\r\n         3     6     9    12    15    18    21    24    27    30    33    36\r\n         4     8    12    16    20    24    28    32    36    40    44    48\r\n         5    10    15    20    25    30    35    40    45    50    55    60\r\n         6    12    18    24    30    36    42    48    54    60    66    72\r\n         7    14    21    28    35    42    49    56    63    70    77    84\r\n         8    16    24    32    40    48    56    64    72    80    88    96\r\n         9    18    27    36    45    54    63    72    81    90    99   108\r\n        10    20    30    40    50    60    70    80    90   100   110   120\r\n        11    22    33    44    55    66    77    88    99   110   121   132\r\n        12    24    36    48    60    72    84    96   108   120   132   144  ];\r\nassert(isequal(ndtimestable(m,n),tt))\r\n\r\n%%\r\nm = 3;\r\nn = 3;\r\ntt = zeros(m,m,m);\r\ntt(:,:,1) = [ 1  2  3\r\n              2  4  6\r\n              3  6  9  ];\r\ntt(:,:,2) = [ 2  4  6\r\n              4  8  12\r\n              6  12 18 ];\r\ntt(:,:,3) = [ 3  6  9\r\n              6  12 18\r\n              9  18 27 ];\r\nassert(isequal(ndtimestable(m,n),tt))\r\n\r\n%%\r\nm = 2;\r\nn = 4;\r\ntt = zeros(m,m,m,m);\r\ntt(:,:,1,1) = ...\r\n  [  1     2\r\n     2     4  ];\r\ntt(:,:,2,1) = ...\r\n  [  2     4\r\n     4     8  ];\r\ntt(:,:,1,2) = ...\r\n  [  2     4\r\n     4     8  ];\r\ntt(:,:,2,2) = ...\r\n  [  4     8\r\n     8    16  ];\r\nassert(isequal(ndtimestable(m,n),tt))\r\n\r\n%%\r\nm = 2;\r\nn = 7;\r\nassert(numel(ndtimestable(m,n)) == m^n);","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":141,"test_suite_updated_at":"2012-01-26T15:30:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T15:17:25.000Z","updated_at":"2026-04-03T03:18:48.000Z","published_at":"2012-01-26T15:30: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eINSTRUCTIONS\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 multi-dimensional variant of the normal multiplication table used to teach elementary students multiplication. In this variant, we are going to produce a table that multiplies the divisors 1 to\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 (input) agains itself in\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\u003ed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Inputting\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\u003ed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 0 should return the number 1 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\u003ed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 1 should return a column vector with the elements 1 to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput:\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 = 3;\\nd = 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\u003eOutput:\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[tt(:,:,1) = [ 1  2  3\\n              2  4  6\\n              3  6  9  ];\\ntt(:,:,2) = [ 2  4  6\\n              4  8  12\\n              6  12 18 ];\\ntt(:,:,3) = [ 3  6  9\\n              6  12 18\\n              9  18 27 ];]]\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":2237,"title":"Mmm! Multi-dimensional Matrix Multiplication ","description":"You have got a couple of multi-dimensional matrices, A and B. And want to multiply them. For the first 2 dimensions, an ordinary matrix multiplication applies. And in the other dimensions? Well, they just act as parallel worlds. All 2D matrices are multiplied, for every element in the other dimensions.\r\nYou may assume that the size in the 1st two dimensions allows simple matrix multiplication: A(:,:,1)*B(:,:,1), so size(A(:,:,1),2) == size(B(:,:,1),1), or either A(:,:,1) is a scalar or B(:,:,1) is a scalar.\r\nIn the other dimensions, the sizes of A and B should be eqaal, size(A,n) == size(B,n), for n\u003e2, or either ndims(A)\u003cn or ndims(B)\u003cn, or either size(A,n)==1 or size(B,n)==1, so one of them is a scalar.\r\n\r\nWrite a function |mtimesm| that does this, and ask Mathworks to include it in the |elmat| toolbox of the Next Release.","description_html":"\u003cp\u003eYou have got a couple of multi-dimensional matrices, A and B. And want to multiply them. For the first 2 dimensions, an ordinary matrix multiplication applies. And in the other dimensions? Well, they just act as parallel worlds. All 2D matrices are multiplied, for every element in the other dimensions.\r\nYou may assume that the size in the 1st two dimensions allows simple matrix multiplication: A(:,:,1)*B(:,:,1), so size(A(:,:,1),2) == size(B(:,:,1),1), or either A(:,:,1) is a scalar or B(:,:,1) is a scalar.\r\nIn the other dimensions, the sizes of A and B should be eqaal, size(A,n) == size(B,n), for n\u0026gt;2, or either ndims(A)\u0026lt;n or ndims(B)\u0026lt;n, or either size(A,n)==1 or size(B,n)==1, so one of them is a scalar.\u003c/p\u003e\u003cp\u003eWrite a function \u003ctt\u003emtimesm\u003c/tt\u003e that does this, and ask Mathworks to include it in the \u003ctt\u003eelmat\u003c/tt\u003e toolbox of the Next Release.\u003c/p\u003e","function_template":"function C = mtimesm(A,B)\r\n  C = A*B;\r\nend","test_suite":"%% case 1\r\nA = 1;\r\nB = 2;\r\nC = mtimesm(A,B);\r\nC_correct = 2;\r\nassert(isequal(C,C_correct))\r\n\r\n%% case 2\r\nA = rand(2,3);\r\nB = rand(3,4);\r\nC = mtimesm(A,B);\r\nC_correct = A*B;\r\nassert(isequal(C,C_correct))\r\n\r\n%% case 3\r\nA = rand(2,3);\r\nB = 2;\r\nC = mtimesm(A,B);\r\nC_correct = 2*A;\r\nassert(isequal(C,C_correct))\r\n\r\n%% case 4\r\nA = rand(2,3,2);\r\nB = rand(3,4,2);\r\nC = mtimesm(A,B);\r\nC_correct = cat(3,A(:,:,1)*B(:,:,1),A(:,:,2)*B(:,:,2));\r\nassert(isequal(C,C_correct))\r\n\r\n%% case 5\r\nA = rand(2,3,3);\r\nB = rand(3,4);\r\nC = mtimesm(A,B);\r\nC_correct = cat(3,A(:,:,1)*B,A(:,:,2)*B,A(:,:,3)*B); \r\nassert(isequal(C,C_correct))\r\n\r\n%% case 6\r\nA = rand(4,3,1,2);\r\nB = rand(3,2,2);\r\nC = mtimesm(A,B);\r\nC_correct(:,:,1,1) = A(:,:,1,1)*B(:,:,1);\r\nC_correct(:,:,1,2) = A(:,:,1,2)*B(:,:,1);\r\nC_correct(:,:,2,1) = A(:,:,1,1)*B(:,:,2);\r\nC_correct(:,:,2,2) = A(:,:,1,2)*B(:,:,2);\r\nassert(isequal(C,C_correct))\r\n\r\n%% case 7\r\nA = rand(4,3,1,2);\r\nB = rand(3,2,1,1,2);\r\nC = mtimesm(A,B);\r\nC_correct(:,:,1,1,1) = A(:,:,1,1)*B(:,:,1,1,1);\r\nC_correct(:,:,1,1,2) = A(:,:,1,1)*B(:,:,1,1,2);\r\nC_correct(:,:,1,2,1) = A(:,:,1,2)*B(:,:,1,1,1);\r\nC_correct(:,:,1,2,2) = A(:,:,1,2)*B(:,:,1,1,2);\r\nassert(isequal(C,C_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":5,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":38,"test_suite_updated_at":"2014-03-07T06:22:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-06T11:17:42.000Z","updated_at":"2026-04-03T03:22:22.000Z","published_at":"2014-03-06T11:17:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have got a couple of multi-dimensional matrices, A and B. And want to multiply them. For the first 2 dimensions, an ordinary matrix multiplication applies. And in the other dimensions? Well, they just act as parallel worlds. All 2D matrices are multiplied, for every element in the other dimensions. You may assume that the size in the 1st two dimensions allows simple matrix multiplication: A(:,:,1)*B(:,:,1), so size(A(:,:,1),2) == size(B(:,:,1),1), or either A(:,:,1) is a scalar or B(:,:,1) is a scalar. In the other dimensions, the sizes of A and B should be eqaal, size(A,n) == size(B,n), for n\u0026gt;2, or either ndims(A)\u0026lt;n or ndims(B)\u0026lt;n, or either size(A,n)==1 or size(B,n)==1, so one of them is a scalar.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function\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\u003emtimesm\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that does this, and ask Mathworks to include it in 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eelmat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e toolbox of the Next Release.\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":1274,"title":"Accurate Division","description":"Given three integers x, y and d, return x/y (as a string) to d significant digits. Remove leading and trailing zeros.\r\n\r\nExample:\r\n\r\nx = 11; y = 7; d = 10;\r\n\r\nz = adiv(x,y,d)\r\n\r\nz=\r\n\r\n1.571428571 ","description_html":"\u003cp\u003eGiven three integers x, y and d, return x/y (as a string) to d significant digits. Remove leading and trailing zeros.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ex = 11; y = 7; d = 10;\u003c/p\u003e\u003cp\u003ez = adiv(x,y,d)\u003c/p\u003e\u003cp\u003ez=\u003c/p\u003e\u003cp\u003e1.571428571\u003c/p\u003e","function_template":"function y = adiv(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 11;\r\ny = 7;\r\nd = 10;\r\nz_correct = '1.571428571';\r\nassert(isequal(adiv(x,y,d),z_correct))\r\n%%\r\nx = 1120;\r\ny = 23;\r\nd = 60;\r\nz_correct = '48.6956521739130434782608695652173913043478260869565217391304';\r\nassert(isequal(adiv(x,y,d),z_correct))\r\n%%\r\nx = 17;\r\ny = 8234;\r\nd = 75;\r\nz_correct = '0.00206461015302404663589992713140636385717755647316006801068739373330094729172';\r\nassert(isequal(adiv(x,y,d),z_correct))\r\n%%\r\nx = 126;\r\ny = 2400;\r\nd = 10;\r\nz_correct = '0.0525';\r\nassert(isequal(adiv(x,y,d),z_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":3399,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-15T15:29:43.000Z","updated_at":"2026-04-03T03:24:38.000Z","published_at":"2013-02-15T15:32:30.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 three integers x, y and d, return x/y (as a string) to d significant digits. Remove leading and trailing zeros.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 = 11; y = 7; d = 10;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ez = adiv(x,y,d)\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\u003ez=\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\u003e1.571428571\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":44065,"title":"Number of even divisors of a given number","description":"Given a Number n, return the number of its even divisors without listing them.\r\n\r\nexample:\r\n\r\nn=14 ; EvenDivisors={2,14} ; y=2\r\n\r\nn=68 ; EvenDivisors={2,34,4,68} ; y=4\r\n\r\nSimilar problems are: \u003chttps://www.mathworks.com/matlabcentral/cody/problems/42791-number-of-divisors-of-a-given-number\u003e \u003chttps://www.mathworks.com/matlabcentral/cody/problems/1025-divisors-of-an-integer\u003e\r\n\r\nn=64 ; EvenDivisors={2,4,8,16,32} ; y=5","description_html":"\u003cp\u003eGiven a Number n, return the number of its even divisors without listing them.\u003c/p\u003e\u003cp\u003eexample:\u003c/p\u003e\u003cp\u003en=14 ; EvenDivisors={2,14} ; y=2\u003c/p\u003e\u003cp\u003en=68 ; EvenDivisors={2,34,4,68} ; y=4\u003c/p\u003e\u003cp\u003eSimilar problems are: \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/42791-number-of-divisors-of-a-given-number\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/42791-number-of-divisors-of-a-given-number\u003c/a\u003e \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/1025-divisors-of-an-integer\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/1025-divisors-of-an-integer\u003c/a\u003e\u003c/p\u003e\u003cp\u003en=64 ; EvenDivisors={2,4,8,16,32} ; y=5\u003c/p\u003e","function_template":"function y = countEvenDivisors(x)\r\n  y = 0;\r\nend","test_suite":"1\r\n%%\r\nfiletext = fileread('countEvenDivisors.m');\r\nassert(isempty(strfind(filetext, 'sqrt')))\r\nassert(isempty(strfind(filetext, 'for')))\r\n2\t\r\n%%\r\nn= 6880 * 2;\r\ny_correct = 24;\r\nassert(isequal(countEvenDivisors(n),y_correct))\r\n3\t\r\n%%\r\nn= 5050 * 2;\r\ny_correct = 12;\r\nassert(isequal(countEvenDivisors(n),y_correct))\r\n4 \t\r\n%%\r\nn= 76576501;\r\ny_correct = 0;\r\nassert(isequal(countEvenDivisors(n),y_correct))\r\n5\t\r\n%%\r\nn= 74 * 2;\r\ny_correct = 4;\r\nassert(isequal(countEvenDivisors(n),y_correct))\r\n6\t\r\n%%\r\nn=14^8 *2 ;\r\ny_correct = 81;\r\nassert(isequal(countEvenDivisors(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":115733,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":"2017-02-13T23:29:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-02-13T23:22:48.000Z","updated_at":"2026-03-09T08:39:00.000Z","published_at":"2017-02-13T23:29: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 a Number n, return the number of its even divisors without listing them.\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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=14 ; EvenDivisors={2,14} ; y=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=68 ; EvenDivisors={2,34,4,68} ; y=4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar problems are:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/42791-number-of-divisors-of-a-given-number\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/42791-number-of-divisors-of-a-given-number\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\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/1025-divisors-of-an-integer\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/1025-divisors-of-an-integer\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\u003en=64 ; EvenDivisors={2,4,8,16,32} ; y=5\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":42775,"title":"Raise a polynomial to a power","description":"In Matlab, polynomials are represented by a vector of coefficients.  For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\r\n\r\nIn this problem, you will be given a polynomial p and a power N.  We would like you to return the vector q that represents the polynominal p^N, the Nth power of p.  If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N.  (N will be a positive integer greater than 0.)","description_html":"\u003cp\u003eIn Matlab, polynomials are represented by a vector of coefficients.  For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\u003c/p\u003e\u003cp\u003eIn this problem, you will be given a polynomial p and a power N.  We would like you to return the vector q that represents the polynominal p^N, the Nth power of p.  If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N.  (N will be a positive integer greater than 0.)\u003c/p\u003e","function_template":"function q = polypow(p,N)\r\n  q = p^N;   \r\nend","test_suite":"%%\r\np=[2];\r\nN=8;\r\ny_correct=256;\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=[1 1];\r\nN=1;\r\ny_correct=[1 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=[1 1];\r\nN=5;\r\ny_correct=[1 5 10 10 5 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=1:5;\r\nN=3;\r\ny_correct=[1 6 21 56 126 234 369 504 594 574 465 300 125];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=5:-1:1;\r\nN=3;\r\ny_correct=[125 300 465 574 594 504 369 234 126 56 21 6 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n\r\n%%\r\np=5:-1:1;\r\nN=1;\r\ny_correct=[5 4 3 2 1];\r\nassert(isequal(polypow(p,N),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":8580,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":"2016-03-16T17:46:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-16T17:30:45.000Z","updated_at":"2026-04-03T02:46:51.000Z","published_at":"2016-03-16T17:44: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\",\"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 Matlab, polynomials are represented by a vector of coefficients. For example, the polynomial p=a*x^2 + b*x + c is represented by the vector p=[a, b, c].\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\u003eIn this problem, you will be given a polynomial p and a power N. We would like you to return the vector q that represents the polynominal p^N, the Nth power of p. If p = (x + 1), for instance, you will be returning the coefficients of (x+1)^N. (N will be a positive integer greater than 0.)\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":2281,"title":"Array ex-OR","description":"There are in MATLAB logical functions such as \r\n_\u003chttp://www.mathworks.co.uk/help/matlab/ref/and.html and\u003e,_ \r\n_\u003chttp://www.mathworks.co.uk/help/matlab/ref/or.html or\u003e_, \r\n_\u003chttp://www.mathworks.co.uk/help/matlab/ref/xor.html xor\u003e_.\r\n\r\n_And_ has its matrix equivalent \r\n_\u003chttp://www.mathworks.co.uk/help/matlab/ref/all.html all\u003e_, \r\nand so has _or_ its \r\n_\u003chttp://www.mathworks.co.uk/help/matlab/ref/any.html any\u003e_.\r\n\r\nWrite a function which is array equivalent for exclusive-OR function _xor_.\r\n\r\nNote that your solution will be scored using its Cody size and complexity.\r\n","description_html":"\u003cp\u003eThere are in MATLAB logical functions such as  \u003ci\u003e\u003ca href = \"http://www.mathworks.co.uk/help/matlab/ref/and.html\"\u003eand\u003c/a\u003e,\u003c/i\u003e  \u003ci\u003e\u003ca href = \"http://www.mathworks.co.uk/help/matlab/ref/or.html\"\u003eor\u003c/a\u003e\u003c/i\u003e,  \u003ci\u003e\u003ca href = \"http://www.mathworks.co.uk/help/matlab/ref/xor.html\"\u003exor\u003c/a\u003e\u003c/i\u003e.\u003c/p\u003e\u003cp\u003e\u003ci\u003eAnd\u003c/i\u003e has its matrix equivalent  \u003ci\u003e\u003ca href = \"http://www.mathworks.co.uk/help/matlab/ref/all.html\"\u003eall\u003c/a\u003e\u003c/i\u003e, \r\nand so has \u003ci\u003eor\u003c/i\u003e its  \u003ci\u003e\u003ca href = \"http://www.mathworks.co.uk/help/matlab/ref/any.html\"\u003eany\u003c/a\u003e\u003c/i\u003e.\u003c/p\u003e\u003cp\u003eWrite a function which is array equivalent for exclusive-OR function \u003ci\u003exor\u003c/i\u003e.\u003c/p\u003e\u003cp\u003eNote that your solution will be scored using its Cody size and complexity.\u003c/p\u003e","function_template":"function out = arr_xor(in) % (in,dim) ?\r\n\r\n  out = xor(in,dim);\r\n\r\nend","test_suite":"%%\r\nx = [0 0 0 0 0 0 1 1 1 1 1 1;\r\n     0 0 0 1 1 1 0 0 0 1 1 1;\r\n     0 1 1 0 1 1 0 1 1 0 1 1;\r\n     0 1 0 1 0 1 0 1 0 1 0 1];\r\ny = [0 0 1 0 0 1 1 1 0 1 1 0];\r\nassert(isequal(arr_xor(x),y))\r\nassert(isequal(arr_xor(x'),zeros(1,4)))\r\n%%\r\nx = randi([0 1],4,12);\r\ny = x(1,:);\r\nfor k=2:4\r\n  y = xor(y,x(k,:));\r\nend\r\nassert(isequal(arr_xor(x),y))\r\n%% optional:\r\n% optional logical output\r\ntry\r\n  assert(islogical(arr_xor(randi([0 1],6,10))))\r\n  penalty = 0;\r\ncatch\r\n  disp('output is not logical, +15 points of penalty')\r\n  penalty = 15;\r\nend\r\n% optional - dim\r\nx = randi([0 1],10);\r\ntry\r\n  assert(isequal(arr_xor(x),arr_xor(x ,1)))\r\n  assert(isequal(arr_xor(x),arr_xor(x',2)'))\r\ncatch\r\n  disp('operating dimention not implemented. +15 points of penalty')\r\n  penalty = penalty+15;\r\nend\r\n% optional - correct for singular dimention\r\ntry\r\n  assert(isequal(arr_xor(1),1))\r\n  assert(isequal(arr_xor([0 0 1 1 0]),0))\r\n  assert(isequal(arr_xor([0;1;1;1;0]),1))\r\ncatch\r\n  disp('incorrect work for vectors, +10 points of penalty');\r\n  penalty=penalty+10;\r\nend\r\n% format conversion\r\ntry\r\n  assert(isequal(arr_xor(['MATLAB';'matlab']'),[0 0]))\r\ncatch\r\n  disp('no conversion from char, +2 points of penalty' )\r\n  penalty=penalty+2;\r\nend\r\ntry\r\n  assert(all(arr_xor(randi(5,5))))\r\n  assert(~any(arr_xor(randi(6,6))))\r\ncatch\r\n  disp('no conversion from double, +5 points of penalty' )\r\n  penalty=penalty+5;\r\nend\r\nfor l=1:4\r\n  stime(l)=tic;\r\n  for k=2:750\r\n    [~]=arr_xor(randi([0 1],k));\r\n  end\r\n  time(l)=toc(stime(l));\r\nend\r\ntime=min(time);\r\ndisp(['elapsed time is ' num2str(time*1000) ' ms.'])\r\n%score calculation\r\nt = mtree('arr_xor.m','-file');\r\nsize = length(t.nodesize);\r\nfeval(@assignin,'caller','score',size + penalty + round(time*5));\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2014-04-11T20:10:24.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-04-11T19:50:53.000Z","updated_at":"2026-04-03T02:47:52.000Z","published_at":"2014-04-11T20:00:15.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"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\u003eThere are in MATLAB logical functions such as \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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/help/matlab/ref/and.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eand\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\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: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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/help/matlab/ref/or.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/help/matlab/ref/xor.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003exor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eAnd\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e has its matrix equivalent \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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/help/matlab/ref/all.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and so has\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\u003eor\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e its \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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/help/matlab/ref/any.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eany\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function which is array equivalent for exclusive-OR function\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\u003exor\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\u003eNote that your solution will be scored using its Cody size and complexity.\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":2499,"title":"Airline Ticket Mod7 Checksum ","description":"There are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12. \r\n\r\n\r\n\r\nWrite a function that returns true if a plane ticket number is valid and false otherwise.","description_html":"\u003cp\u003eThere are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12.\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a plane ticket number is valid and false otherwise.\u003c/p\u003e","function_template":"function b = isTicketValid(T)\r\n\r\nend","test_suite":"%%\r\nT=1234567891011;\r\nb_correct=0;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n%%\r\nT=2355211846932;\r\nb_correct=0;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n%%\r\nT=2355211846934;\r\nb_correct=1;\r\nassert(isequal(isTicketValid(T),b_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":379,"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":"2014-08-09T16:26:01.000Z","updated_at":"2026-04-03T02:48:52.000Z","published_at":"2014-08-09T16:26: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\",\"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\u003eThere are 13 digits in an airline ticket number. If an airline ticket number is valid, the 13th digit should be the remainder of division by seven of the first 12.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns true if a plane ticket number is valid and false otherwise.\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":2810,"title":"Determinant without using det()","description":"Given a square matrix A, compute the \u003chttp://en.wikipedia.org/wiki/Determinant determinant\u003e of A.\r\n\r\nNote that you may not use the built-in MATLAB function det(). This will be checked.\r\n\r\n*Examples:*\r\n\r\n    A = 1;\r\n    y = 1;\r\n\r\n    A = [1 2; 3 4];\r\n    y = -2;","description_html":"\u003cp\u003eGiven a square matrix A, compute the \u003ca href = \"http://en.wikipedia.org/wiki/Determinant\"\u003edeterminant\u003c/a\u003e of A.\u003c/p\u003e\u003cp\u003eNote that you may not use the built-in MATLAB function det(). This will be checked.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e\u003c/p\u003e\u003cpre\u003e    A = 1;\r\n    y = 1;\u003c/pre\u003e\u003cpre\u003e    A = [1 2; 3 4];\r\n    y = -2;\u003c/pre\u003e","function_template":"function y = det2(A)\r\n  y = A;\r\nend","test_suite":"%% Tests whether you have used det()\r\nassert(isempty(regexpi(evalc('type det2'),'det *(')))\r\n\r\n%%\r\nA = 23;\r\nabserr=abs(det(A)-det2(A));\r\nrelerr=abserr/abs(det(A));\r\nassert(abserr\u003c1e-10 | relerr\u003c1e-10)\r\n\r\n%%\r\nA = magic(2);\r\nabserr=abs(det(A)-det2(A));\r\nrelerr=abserr/abs(det(A));\r\nassert(abserr\u003c1e-10 | relerr\u003c1e-10)\r\n\r\n%%\r\nA = magic(5);\r\nabserr=abs(det(A)-det2(A));\r\nrelerr=abserr/abs(det(A));\r\nassert(abserr\u003c1e-10 | relerr\u003c1e-10)\r\n\r\n%%\r\nA = hilb(4);\r\nabserr=abs(det(A)-det2(A));\r\nrelerr=abserr/abs(det(A));\r\nassert(abserr\u003c1e-10 | relerr\u003c1e-10)\r\n\r\n%%\r\nA = [10 7 2 9; 10 1 1 8; 7 10 1 10; 3 7 6 7];\r\nabserr=abs(det(A)-det2(A));\r\nrelerr=abserr/abs(det(A));\r\nassert(abserr\u003c1e-10 | relerr\u003c1e-10)\r\n\r\n%%\r\nA = [6 8 5 8 8 8 9 5; 3 8 3 8 8 5 1 3; 6 4 4 3 6 3 3 8; 6 4 1 3 3 3 7 8;\r\n     6 3 5 3 4 8 6 9; 5 7 4 7 5 6 4 3; 1 4 9 9 1 4 6 9; 7 1 5 6 4 1 1 1];\r\nabserr=abs(det(A)-det2(A));\r\nrelerr=abserr/abs(det(A));\r\nassert(abserr\u003c1e-10 | relerr\u003c1e-10)\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":33611,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-01-03T18:44:00.000Z","updated_at":"2026-04-03T02:49:56.000Z","published_at":"2015-01-03T20:17:57.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a square matrix A, compute the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Determinant\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edeterminant\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of 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\u003eNote that you may not use the built-in MATLAB function det(). This will be checked.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\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[    A = 1;\\n    y = 1;\\n\\n    A = [1 2; 3 4];\\n    y = -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":43560,"title":"Calculate the hypotenuse of a right triangle without using ^ and sqrt ()","description":"Find out the hypotenuse of right triangle.\r\n\r\n\r\nSay a = 4, b = 3  then c = 5 \r\n\r\n\r\nPlease don't use ^ and sqrt() function. ","description_html":"\u003cp\u003eFind out the hypotenuse of right triangle.\u003c/p\u003e\u003cp\u003eSay a = 4, b = 3  then c = 5\u003c/p\u003e\u003cp\u003ePlease don't use ^ and sqrt() function.\u003c/p\u003e","function_template":"function y = hypotenuse(a,b)\r\n  y = sqrt(a^2+b^2)\r\nend","test_suite":"%%\r\na = 3;\r\nb= 4;\r\ny_correct = 5;\r\nassert(abs(hypotenuse(a,b)-y_correct)\u003c0.0001)\r\n\r\n%%\r\na = 2;\r\nb = pi * 2;\r\ny_correct = sqrt(a^2+b^2);\r\nassert(abs(hypotenuse(a,b)-y_correct)\u003c0.0001)\r\n\r\n%%\r\na = randi(10);\r\nb = randi(13);\r\ny_correct = sqrt(a^2+b^2);\r\nassert(abs(hypotenuse(a,b)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nuser_solution = fileread('hypotenuse.m');\r\nassert(isempty(strfind(user_solution,'^')));\r\n\r\n%%\r\nassessFunctionAbsence({'sqrt'}, 'FileName', 'hypotenuse.m');\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":14644,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":104,"test_suite_updated_at":"2016-11-30T19:36:02.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-16T08:20:00.000Z","updated_at":"2026-04-03T02:50:47.000Z","published_at":"2016-10-16T08:20:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eFind out the hypotenuse of right triangle.\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\u003eSay a = 4, b = 3 then c = 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\u003ePlease don't use ^ and sqrt() function.\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":43564,"title":"Calculate sin(x) without sin(x)","description":"Calculate\r\ny = sin(x)\r\n\r\nx = 0 -\u003e y= 0\r\n\r\nwithout the use of sin(x) or cos(x)\r\n","description_html":"\u003cp\u003eCalculate\r\ny = sin(x)\u003c/p\u003e\u003cp\u003ex = 0 -\u0026gt; y= 0\u003c/p\u003e\u003cp\u003ewithout the use of sin(x) or cos(x)\u003c/p\u003e","function_template":"function y = my_func(x)\r\n  y = sin(x);\r\nend","test_suite":"x = 0;\r\ny_correct = 0;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = -pi/2;\r\ny_correct = sin(x);\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = rand(1)*2*pi;\r\ny_correct = sin(x);\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nassessFunctionAbsence({'cos', 'sin'}, 'FileName', 'my_func.m');\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":14644,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":119,"test_suite_updated_at":"2016-12-01T18:41:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-16T10:50:54.000Z","updated_at":"2026-04-03T02:51:49.000Z","published_at":"2016-10-16T10:50: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\",\"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\u003eCalculate y = sin(x)\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 = 0 -\u0026gt; y= 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\u003ewithout the use of sin(x) or cos(x)\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":43563,"title":"Calculate cosine without cos(x)","description":"Solve cos(x).\r\n\r\nThe use of the function cos() and sin() is not allowed.","description_html":"\u003cp\u003eSolve cos(x).\u003c/p\u003e\u003cp\u003eThe use of the function cos() and sin() is not allowed.\u003c/p\u003e","function_template":"function y = my_func(x)\r\n  y = cos(x);\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 1;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = pi/2;\r\ny_correct = 0;\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nx = rand(1)*2*pi;\r\ny_correct = cos(x);\r\nassert(abs(my_func(x)-y_correct)\u003c0.0001)\r\n\r\n%%\r\nassessFunctionAbsence({'sin','cos'}, 'FileName', 'my_func.m')\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":14644,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":"2016-12-01T18:38:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-16T10:35:20.000Z","updated_at":"2026-04-03T02:52:46.000Z","published_at":"2016-10-16T10:42: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\",\"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\u003eSolve cos(x).\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 use of the function cos() and sin() is not allowed.\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":43738,"title":"Negative without '-'","description":"Simple: return a negative number without using the '-' sign.\r\n\r\nThanks to Problem \u003chttps://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers/solutions/new 813\u003e for help with test suite.","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 25.5px; vertical-align: baseline; perspective-origin: 332px 25.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 10.5px; white-space: pre-wrap; perspective-origin: 309px 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eSimple: return a negative number without using the '-' sign.\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 10.5px; white-space: pre-wrap; perspective-origin: 309px 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; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThanks to Problem\u003c/span\u003e\u003c/span\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=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers/solutions/new\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e813\u003c/span\u003e\u003c/span\u003e\u003c/a\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=\"\"\u003e for help with test suite.\u003c/span\u003e\u003c/span\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 = 1;\r\ny_correct = -1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext, '*')),'sign * forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '-')),'- forbidden')\r\n%assert(isempty(strfind(filetext, '0')),'0 forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot forbidden')\r\nassert(isempty(strfind(filetext, '''')),'string forbidden')\r\n\r\n%%\r\nx = 8;\r\ny_correct = -8;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 8;\r\ny_correct = -8;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = -148;\r\ny_correct = 148;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = randi([1 58]);\r\ny_correct = -x;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = -pi;\r\ny_correct = pi;\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":93456,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":71,"test_suite_updated_at":"2020-10-08T13:15:19.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-12-06T23:54:31.000Z","updated_at":"2026-04-03T02:55:07.000Z","published_at":"2016-12-06T23:54:30.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\u003eSimple: return a negative number without using the '-' sign.\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\u003eThanks to Problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers/solutions/new\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e813\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for help with test suite.\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":44159,"title":"calculate PI without using pi function","description":"There are many methods to get the pi(Ratio of circumference to diameter). \r\nYou should get pi without using the pi function in MATLAB.\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Pi\u003e The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.","description_html":"\u003cp\u003eThere are many methods to get the pi(Ratio of circumference to diameter). \r\nYou should get pi without using the pi function in MATLAB.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Pi\"\u003ehttps://en.wikipedia.org/wiki/Pi\u003c/a\u003e The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.\u003c/p\u003e","function_template":"function PAI = calculate_PAI\r\n  PAI = ...;\r\nend","test_suite":"%%\r\nassert(abs(calculate_PAI-pi)\u003c1e-7);\r\n%%\r\nfiletext = fileread('calculate_PAI.m');\r\nassert(isempty(strfind(filetext, 'pi')),'pi forbidden');\r\nassert(isempty(strfind(filetext, '3.14159')),'3.14159 forbidden');\r\nassert(isempty(strfind(filetext, 'str')),'str function forbidden');","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":125749,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":108,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-05-14T04:46:10.000Z","updated_at":"2026-04-03T02:56:43.000Z","published_at":"2017-05-14T04:46:10.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eThere are many methods to get the pi(Ratio of circumference to diameter). You should get pi without using the pi function in MATLAB.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Pi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Pi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; The Chinese mathematician Zu Chongzhi, around 480 AD, calculated that π ≈ 355/113. With a correct value for its seven first decimal digits, this value of 3. 141592920 , remained the most accurate approximation of π available for the next 800 years.\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":43650,"title":"Church Encoding","description":"Church encoded numeral is a function which takes two arguments _f_ and _x_ and applies _f_ to _x_ several times.\r\n\r\nFor example, if _c_ is a church numeral 3, then the following holds.\r\n_c_(f,x) = f(f(f(x)))\r\n\r\nWrite a function named _church(n)_. Input _n_ is an nonnegative integer. Output is the church encoded numeral of _n_.\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Church_encoding\u003e","description_html":"\u003cp\u003eChurch encoded numeral is a function which takes two arguments \u003ci\u003ef\u003c/i\u003e and \u003ci\u003ex\u003c/i\u003e and applies \u003ci\u003ef\u003c/i\u003e to \u003ci\u003ex\u003c/i\u003e several times.\u003c/p\u003e\u003cp\u003eFor example, if \u003ci\u003ec\u003c/i\u003e is a church numeral 3, then the following holds. \u003ci\u003ec\u003c/i\u003e(f,x) = f(f(f(x)))\u003c/p\u003e\u003cp\u003eWrite a function named \u003ci\u003echurch(n)\u003c/i\u003e. Input \u003ci\u003en\u003c/i\u003e is an nonnegative integer. Output is the church encoded numeral of \u003ci\u003en\u003c/i\u003e.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Church_encoding\"\u003ehttps://en.wikipedia.org/wiki/Church_encoding\u003c/a\u003e\u003c/p\u003e","function_template":"function y = church(n)\r\n  y = @(f,x)f(f(f(x)));\r\nend","test_suite":"%%\r\nincr = @(a)a+1\r\nc = church(0)\r\nassert(isequal(c(incr,100),100))\r\n\r\n%%\r\nincr = @(a)a+1\r\nc = church(3)\r\nassert(isequal(c(incr,0),3))\r\n\r\n%%\r\ntwice = @(a)a*2\r\nc = church(5)\r\nassert(isequal(c(twice,1),32))\r\n\r\n%%\r\nincr = @(a)a+1\r\nc = church(10)\r\nassert(isequal(c(incr,10),20))\r\n\r\n%%\r\ntwice = @(a)a*2\r\nc = church(10)\r\nassert(isequal(c(twice,3),3072))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":100197,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":"2016-11-08T14:44:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-11-08T14:37:05.000Z","updated_at":"2026-04-03T02:58:00.000Z","published_at":"2016-11-08T14:37:11.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\u003eChurch encoded numeral is a function which takes two arguments\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\u003ef\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and applies\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\u003ef\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e several times.\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\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a church numeral 3, then the following holds.\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(f,x) = f(f(f(x)))\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function named\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\u003echurch(n)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Input\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 is an nonnegative integer. Output is the church encoded numeral of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Church_encoding\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Church_encoding\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":43968,"title":"Concatenated roots","description":"Which is the value of this infinte concatenated roots?\r\n\r\n\u003c\u003chttps://s27.postimg.org/i4hkin7xf/Code_Cogs_Eqn.gif\u003e\u003e\r\n\r\n\r\nNote: If image server is not available, the equation was:\r\n\r\n  x*sqrt(x*cuberoot(x*fourthroot(x*fifthroot(x*sixthroot(...)))))\r\n\r\nTip: sum(1/n!)","description_html":"\u003cp\u003eWhich is the value of this infinte concatenated roots?\u003c/p\u003e\u003cimg src = \"https://s27.postimg.org/i4hkin7xf/Code_Cogs_Eqn.gif\"\u003e\u003cp\u003eNote: If image server is not available, the equation was:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex*sqrt(x*cuberoot(x*fourthroot(x*fifthroot(x*sixthroot(...)))))\r\n\u003c/pre\u003e\u003cp\u003eTip: sum(1/n!)\u003c/p\u003e","function_template":"function y = infinteroots(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny = 1;\r\nassert(abs(infinteroots(x)-y)\u003c1e-11)\r\n\r\n%%\r\nx = 10;\r\ny = 52.2735299670437;\r\nassert(abs(infinteroots(x)-y)\u003c1e-11)\r\n\r\n%%\r\nx=5;\r\ny=15.8864718332426;\r\nassert(abs(infinteroots(x)-y)\u003c1e-11)\r\n\r\n%%\r\nx=6;\r\ny=21.7311722059576;\r\nassert(abs(infinteroots(x)-y)\u003c1e-11)\r\n\r\n%%\r\nx=4;\r\ny=10.827015106694;\r\nassert(abs(infinteroots(x)-y)\u003c1e-11)\r\n\r\n%%\r\nx=3.2;\r\ny=7.37887287693964;\r\nassert(abs(infinteroots(x)-y)\u003c1e-11)\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":12767,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-12-25T20:58:32.000Z","updated_at":"2026-04-03T02:58:43.000Z","published_at":"2016-12-25T20:59: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\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.gif\"}],\"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\u003eWhich is the value of this infinte concatenated roots?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: If image server is not available, the equation was:\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*sqrt(x*cuberoot(x*fourthroot(x*fifthroot(x*sixthroot(...)))))]]\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\u003eTip: sum(1/n!)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"},{\"partUri\":\"/media/image1.gif\",\"contentType\":\"image/gif\",\"content\":\"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAC1QTFRFeHh4k5OT9vb2gYGBnJycwMDAt7e3ioqK0tLS7e3t29vb5OTkycnJ////b29vvCMpXwAAAKZJREFUeNq8k0sWwyAIAEXzh3D/41ZrahASklXZ6cxTEAz8EOGFsDvxTyECM0RHgJIwOEIt6VFYX19BAd0kKe8vTpn0vY9uheXoQjGYrICtf9mg3Qgo+kt12fE4sxQwaGFQXCdJmmshaV4EnKYxmgMO/pvJVJ92NrwNbSpnrJafUz1kYbRcjP121ii4EKDVIPnVx+n4hdBzKyhuBM21YLgSLOePAAMAW0UziCh1I3kAAAAASUVORK5CYII=\"}]}"},{"id":44467,"title":"Product of Each Column","description":"Given a matrix |mat| with |n| columns, return a row vector |v| of length |n|, where every element in |v| is the product of the |n|-th column.\r\n\r\n\r\n*You cannot use MATLAB |Prod()| function*\r\n\r\n\r\nExample:\r\n\r\n  Input: mat = [ 1,  2,  3,  4;\r\n                 5,  6,  7,  2;\r\n                 2,  3,  4,  5]\r\n  Output: v  = [10, 36, 84, 40]","description_html":"\u003cp\u003eGiven a matrix \u003ctt\u003emat\u003c/tt\u003e with \u003ctt\u003en\u003c/tt\u003e columns, return a row vector \u003ctt\u003ev\u003c/tt\u003e of length \u003ctt\u003en\u003c/tt\u003e, where every element in \u003ctt\u003ev\u003c/tt\u003e is the product of the \u003ctt\u003en\u003c/tt\u003e-th column.\u003c/p\u003e\u003cp\u003e\u003cb\u003eYou cannot use MATLAB \u003ctt\u003eProd()\u003c/tt\u003e function\u003c/b\u003e\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput: mat = [ 1,  2,  3,  4;\r\n               5,  6,  7,  2;\r\n               2,  3,  4,  5]\r\nOutput: v  = [10, 36, 84, 40]\r\n\u003c/pre\u003e","function_template":"function v = myProd(mat)\r\n    v = mat(1, 1);\r\nend","test_suite":"%%\r\nfiletext = fileread('myProd.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('myProd.m');\r\nassert(isempty(strfind(filetext, 'prod')),'Cannot use prod() function')\r\n\r\n%%\r\nmat = ones(5);\r\nv_correct = ones(1, 5);\r\nassert(isequal(myProd(mat),v_correct))\r\n\r\n%%\r\nmat = [ 1,  2,  3,  4; 5,  6,  7,  2; 2,  3,  4,  5];\r\nv_correct  = [10, 36, 84, 40];\r\nassert(isequal(myProd(mat),prod(mat)))\r\n\r\n%%\r\nm = randi([5,15]);\r\nn = randi([5,15]);\r\nmat = randi(5, n, m);\r\nv_correct = prod(mat);\r\nassert(isequal(myProd(mat),prod(mat)))\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":408,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T21:40:40.000Z","updated_at":"2026-04-03T02:59:54.000Z","published_at":"2017-12-24T21:40:40.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 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 columns, return 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 length\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, where every element in\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 is the product of 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: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-th column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eYou cannot use MATLAB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProd()\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e function\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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: mat = [ 1,  2,  3,  4;\\n               5,  6,  7,  2;\\n               2,  3,  4,  5]\\nOutput: v  = [10, 36, 84, 40]]]\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":1502,"title":"Perl 1: push","description":"_This is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?_\r\n \r\nPushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type.\r\nExample:\r\n\r\n  x=[1 2 3 4 5]\r\n  [x, num]=push(x, [6 7 8])\r\n\r\nthen\r\n\r\n  x=[1 2 3 4 5 6 8]\r\n  [x, num]=8\r\n","description_html":"\u003cp\u003e\u003ci\u003eThis is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?\u003c/i\u003e\u003c/p\u003e\u003cp\u003ePushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3 4 5]\r\n[x, num]=push(x, [6 7 8])\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[1 2 3 4 5 6 8]\r\n[x, num]=8\r\n\u003c/pre\u003e","function_template":"function y=push(x, list)\r\n","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny = [6 7 8];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6 7 8];\r\nnum_correct = 8;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny = 6;\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6];\r\nnum_correct = 6;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [1 2 3 4 5]';\r\ny = [6 7 8];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3 4 5 6 7 8]';\r\nnum_correct = 8;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [];\r\ny = [1 2 3];\r\n[x, num] = push(x, y);\r\ny_correct = [1 2 3];\r\nnum_correct = 3;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));\r\n\r\n%%\r\nx = [0.5 8.4 9.6];\r\ny = [12.0 pi];\r\n[x, num] = push(x, y);\r\ny_correct = [0.5 8.4 9.6 12.0 pi];\r\nnum_correct = 5;\r\nassert(isequal(x,y_correct) \u0026 isequal(num, num_correct));","published":true,"deleted":false,"likes_count":0,"comments_count":4,"created_by":750,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":"2013-05-13T15:04:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-12T13:28:10.000Z","updated_at":"2026-04-03T03:01:36.000Z","published_at":"2013-05-12T13:45: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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThis is part of a series of perl function which were very helpful for many perl programmers. Could you implement it in Matlab?\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\u003ePushes the values of list onto the end of the array and returns the number of elements in the new array. The output vector should be of the same type (column or row array) as the input vector x regardless of the list append type. Example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x=[1 2 3 4 5]\\n[x, num]=push(x, [6 7 8])]]\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\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 4 5 6 8]\\n[x, num]=8]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44486,"title":"Vector push","description":"Append an element |x| to the end of the vector |v| and return both the extended vector and the new number of its elements. |x| can be a vector as well.\r\n\r\nIn cases where |v| is a row vector and |x| is a column vector, or vice versa, |v| should remain a row/column vector.\r\nWhen |v| is originally empty, it should preserve the dimensions of |x.|\r\n\r\nFor example:\r\n\r\n  v = 1:5;\r\n  [v, n] = push(v, [6;7;8]);\r\n\r\nResults in:\r\n\r\n  v = 1:8;\r\n  n = 8;\r\n\r\n  ","description_html":"\u003cp\u003eAppend an element \u003ctt\u003ex\u003c/tt\u003e to the end of the vector \u003ctt\u003ev\u003c/tt\u003e and return both the extended vector and the new number of its elements. \u003ctt\u003ex\u003c/tt\u003e can be a vector as well.\u003c/p\u003e\u003cp\u003eIn cases where \u003ctt\u003ev\u003c/tt\u003e is a row vector and \u003ctt\u003ex\u003c/tt\u003e is a column vector, or vice versa, \u003ctt\u003ev\u003c/tt\u003e should remain a row/column vector.\r\nWhen \u003ctt\u003ev\u003c/tt\u003e is originally empty, it should preserve the dimensions of \u003ctt\u003ex.\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = 1:5;\r\n[v, n] = push(v, [6;7;8]);\r\n\u003c/pre\u003e\u003cp\u003eResults in:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = 1:8;\r\nn = 8;\r\n\u003c/pre\u003e","function_template":"function [v, n] = push(v, x)\r\n    n = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('push.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1, 2, 7];\r\nx = [];\r\n[v, n] = push(v, x);\r\nv_correct = [1, 2, 7];\r\nn_correct = 3;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_correct));\r\n\r\n%%\r\nv = [];\r\nx = [5, 6, 8];\r\n[v, n] = push(v, x);\r\nv_correct = [5, 6, 8];\r\nn_correct = 3;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_correct));\r\n\r\n\r\n%%\r\nv = [];\r\nx = [7; 3; 9; 4];\r\n[v, n] = push(v, x);\r\nv_correct = [7; 3; 9; 4];\r\nn_correct = 4;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_correct));\r\n\r\n%%\r\nv1 = randi(10, 1, 5);\r\nx = 5;\r\n[v, n] = push(v1, x);\r\nv_correct = [v1, 5];\r\nn_correct = 6;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_correct));\r\n\r\n%%\r\nv = [ones(4, 1)];\r\nx = [3, 5];\r\n[v, n] = push(v, x);\r\nv_correct = [1; 1; 1; 1; 3; 5];\r\nn_correct = 6;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_correct));\r\n\r\n%%\r\nv = [zeros(1, 4)];\r\nx = [3; 0];\r\n[v, n] = push(v, x);\r\nv_correct = [0, 0, 0, 0, 3, 0];\r\nn_correct = 6;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_correct));\r\n\r\nv = [8, 2];\r\nx = [];\r\n[v, n] = push(v, x);\r\nv_correct = [8, 2];\r\nn_correct = 2;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(n, n_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":403,"test_suite_updated_at":"2018-01-07T22:00:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T12:51:53.000Z","updated_at":"2026-04-03T03:02:18.000Z","published_at":"2018-01-07T19:02: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\u003eAppend an element\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the end of the 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 and return both the extended vector and the new number of its elements.\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e can be a vector as well.\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 cases where\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 is a row vector 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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a column vector, or vice versa,\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 should remain a row/column vector. When\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 is originally empty, it should preserve the dimensions 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex.\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:\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 = 1:5;\\n[v, n] = push(v, [6;7;8]);]]\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\u003eResults in:\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 = 1:8;\\nn = 8;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44490,"title":"Vector pop","description":"Take |n| elements from the end of the vector |v| and return both the shorten vector |v| and the |n| elements in a separate vector |w|.\r\n\r\nIf  |v| has less elements than |n|, the shorten vector |v| should be empty and all elements should exist in |w|.\r\n\r\n*Example 1*\r\n\r\n  v = 1:10\r\n  [v, w] = pop(v, 3);\r\n\r\nThen:\r\n\r\n  v = 1:7\r\n  w = 8:10\r\n\r\n*Example 2*\r\n\r\n  v = [1; 2; 3]\r\n  [v, w] = pop(v, 5);\r\n\r\nThen:\r\n\r\n  v = []\r\n  w = [1; 2; 3]","description_html":"\u003cp\u003eTake \u003ctt\u003en\u003c/tt\u003e elements from the end of the vector \u003ctt\u003ev\u003c/tt\u003e and return both the shorten vector \u003ctt\u003ev\u003c/tt\u003e and the \u003ctt\u003en\u003c/tt\u003e elements in a separate vector \u003ctt\u003ew\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf  \u003ctt\u003ev\u003c/tt\u003e has less elements than \u003ctt\u003en\u003c/tt\u003e, the shorten vector \u003ctt\u003ev\u003c/tt\u003e should be empty and all elements should exist in \u003ctt\u003ew\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample 1\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = 1:10\r\n[v, w] = pop(v, 3);\r\n\u003c/pre\u003e\u003cp\u003eThen:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = 1:7\r\nw = 8:10\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eExample 2\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = [1; 2; 3]\r\n[v, w] = pop(v, 5);\r\n\u003c/pre\u003e\u003cp\u003eThen:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = []\r\nw = [1; 2; 3]\r\n\u003c/pre\u003e","function_template":"function [v, w] = pop(v, n)\r\n    w = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('pop.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1, 2, 7];\r\nn = 0;\r\n[v, w] = pop(v, n);\r\nv_correct = [1, 2, 7];\r\nassert(isequal(v, v_correct));\r\nassert(isempty(w));\r\n\r\n%%\r\nv = 1:10;\r\nn = 3;\r\n[v, w] = pop(v, n);\r\nv_correct = 1:7;\r\nw_correct = 8:10;\r\nassert(isequal(v, v_correct));\r\nassert(isequal(w, w_correct));\r\n\r\n%%\r\nv = [1; 2; 3]\r\nn = 5;\r\n[v, w] = pop(v, n);\r\nw_correct = [1; 2; 3];\r\nassert(isempty(v));\r\nassert(isequal(w, w_correct));\r\n\r\n%%\r\nv = ones(10, 1);\r\nn = 4;\r\n[v, w] = pop(v, n);\r\nv_correct = ones(6, 1);\r\nw_correct = ones(4, 1);\r\nassert(isequal(v, v_correct));\r\nassert(isequal(w, w_correct));\r\n\r\n%%\r\nv = zeros(1, 8);\r\nn = 2;\r\n[v, w] = pop(v, n);\r\nv_correct = zeros(1, 6);\r\nw_correct = zeros(1, 2);\r\nassert(isequal(v, v_correct));\r\nassert(isequal(w, w_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":399,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T20:48:40.000Z","updated_at":"2026-04-03T03:04:35.000Z","published_at":"2018-01-07T20:48:40.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\u003eTake\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 from the end of the 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 and return both the shorten 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 and 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: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 in a separate 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\u003ew\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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e has less elements than\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, the shorten 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 should be empty and all elements should exist in\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\u003ew\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[v = 1:10\\n[v, w] = pop(v, 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\u003eThen:\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 = 1:7\\nw = 8:10]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample 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[v = [1; 2; 3]\\n[v, w] = pop(v, 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\u003eThen:\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 = []\\nw = [1; 2; 3]]]\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":44491,"title":"Shuffle","description":"Shuffle a vector by breaking it up to segments of |n| elements, and rearranging them in a reversed order.\r\n\r\nFor example, the vector:\r\n\r\n vector = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n\r\nshould be shffuled by segments of |n=3| like so:\r\n\r\n cetvor = [8,9,10,   5,6,7,   2,3,4,   1]\r\n\r\nThe shuffled vector should have the same dimensions as the original one.\r\n\r\n*You must call the functions \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44486 push()\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44490 pop()\u003e.*","description_html":"\u003cp\u003eShuffle a vector by breaking it up to segments of \u003ctt\u003en\u003c/tt\u003e elements, and rearranging them in a reversed order.\u003c/p\u003e\u003cp\u003eFor example, the vector:\u003c/p\u003e\u003cpre\u003e vector = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\u003c/pre\u003e\u003cp\u003eshould be shffuled by segments of \u003ctt\u003en=3\u003c/tt\u003e like so:\u003c/p\u003e\u003cpre\u003e cetvor = [8,9,10,   5,6,7,   2,3,4,   1]\u003c/pre\u003e\u003cp\u003eThe shuffled vector should have the same dimensions as the original one.\u003c/p\u003e\u003cp\u003e\u003cb\u003eYou must call the functions \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44486\"\u003epush()\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44490\"\u003epop()\u003c/a\u003e.\u003c/b\u003e\u003c/p\u003e","function_template":"function cetvor = shuffle(vector, n)\r\n    cetvor = vector;\r\nend\r\n\r\n% You must call the following functions from the shuffle() function\r\n% (copy-paste your solutions)\r\nfunction [v, n] = push(v, x)\r\n    n = [];\r\nend\r\n\r\nfunction [v, w] = pop(v, n)\r\n    w = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('shuffle.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1, 2, 3, 4, 5, 6, 7, 8];\r\nn = 1;\r\nw_correct = 8 : -1 : 1;\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1; 2; 3; 4; 5; 6; 7; 8];\r\nn = 2;\r\nw_correct = [7;8;  5;6;  3;4;  1;2];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1, 2, 3, 4, 5, 6, 7, 8];\r\nn = 3;\r\nw_correct = [6,7,8,  3,4,5,  1,2];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1; 2; 3; 4; 5; 6; 7; 8];\r\nn = 4;\r\nw_correct = [5;6;7;8;  1;2;3;4];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1, 2, 3, 4, 5, 6, 7, 8];\r\nn = 5;\r\nw_correct = [4,5,6,7,8,  1,2,3];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1; 2; 3; 4; 5; 6; 7; 8];\r\nn = 6;\r\nw_correct = [3;4;5;6;7;8;  1;2];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1, 2, 3, 4, 5, 6, 7, 8];\r\nn = 7;\r\nw_correct = [2,3,4,5,6,7,8,  1];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1; 2; 3; 4; 5; 6; 7; 8];\r\nn = 8;\r\nw_correct = [1;2;3;4;5;6;7;8];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n\r\n%%\r\nv = [1, 2, 3, 4, 5, 6, 7, 8];\r\nn = 9;\r\nw_correct = [1,2,3,4,5,6,7,8];\r\nassert(isequal(shuffle(v, n), w_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":333,"test_suite_updated_at":"2018-01-07T22:04:15.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T21:23:35.000Z","updated_at":"2026-04-03T03:05:46.000Z","published_at":"2018-01-07T22:04:15.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"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\u003eShuffle a vector by breaking it up to segments 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: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, and rearranging them in a reversed order.\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, the vector:\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[ vector = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\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\u003eshould be shffuled by segments 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en=3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e like so:\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[ cetvor = [8,9,10,   5,6,7,   2,3,4,   1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe shuffled vector should have the same dimensions as the original one.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eYou must call the functions\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44486\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003epush()\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44490\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003epop()\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\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":44498,"title":"Please check the last row","description":"We have data of matrix, that is input.\r\nThat contains 2 or more rows and the last row should contain the average of each column,\r\nbut some matrices have no average row.\r\n\r\nPlease check the last row is the average row.\r\nIf it is OK, please output as it is. Otherwise, please calculate the average, add it to a matrix, and output.\r\n\r\neg1 data = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5] \r\n\r\n\u003e\u003e\u003e\r\noutput = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5]  \r\n\r\neg2\r\ndata = [1 3 6 7 9 ; 3 5 6 9 1] \r\n\r\n\u003e\u003e\u003e output = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5]","description_html":"\u003cp\u003eWe have data of matrix, that is input.\r\nThat contains 2 or more rows and the last row should contain the average of each column,\r\nbut some matrices have no average row.\u003c/p\u003e\u003cp\u003ePlease check the last row is the average row.\r\nIf it is OK, please output as it is. Otherwise, please calculate the average, add it to a matrix, and output.\u003c/p\u003e\u003cp\u003eeg1 data = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5]\u003c/p\u003e\u003cp\u003e\u0026gt;\u0026gt;\u0026gt;\r\noutput = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5]\u003c/p\u003e\u003cp\u003eeg2\r\ndata = [1 3 6 7 9 ; 3 5 6 9 1]\u003c/p\u003e\u003cp\u003e\u0026gt;\u0026gt;\u0026gt; output = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5]\u003c/p\u003e","function_template":"function output = check_ave(data)\r\n  output = [];\r\nend","test_suite":"%% 1 NG\r\ndata=[...\r\n    1 3 6 7 9\r\n    3 5 6 9 1];\r\noutput_correct =[...\r\n    1 3 6 7 9\r\n    3 5 6 9 1\r\n    2 4 6 8 5];\r\nassert(isequal(check_ave(data),output_correct))\r\n\r\n%% 2 OK\r\ndata=[...\r\n    1 3 6 7 9\r\n    3 5 6 9 1\r\n    2 4 6 8 5];\r\noutput_correct = data;\r\nassert(isequal(check_ave(data),output_correct))\r\n\r\n%% 3 OK\r\ndata=[...\r\n    2 3 0 0 6\r\n    1 3 6 0 1\r\n    3 3 6 9 2\r\n    2 3 4 3 3];\r\noutput_correct = data;\r\nassert(isequal(check_ave(data),output_correct))\r\n\r\n%% 4 NG\r\ndata=[...\r\n    2 3 0 0 6\r\n    1 3 6 0 1\r\n    3 3 6 9 2];\r\noutput_correct =[...\r\n    2 3 0 0 6\r\n    1 3 6 0 1\r\n    3 3 6 9 2\r\n    2 3 4 3 3];\r\nassert(isequal(check_ave(data),output_correct))\r\n\r\n%% 5 NG\r\ndata = [1:1000;999:-1:0];\r\noutput_correct =[data;repmat(500,1,1000)];\r\nassert(isequal(check_ave(data),output_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":137687,"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-01-14T08:02:37.000Z","updated_at":"2026-04-03T03:07:04.000Z","published_at":"2018-01-14T08:55: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\",\"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\u003eWe have data of matrix, that is input. That contains 2 or more rows and the last row should contain the average of each column, but some matrices have no average 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\u003ePlease check the last row is the average row. If it is OK, please output as it is. Otherwise, please calculate the average, add it to a matrix, and output.\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\u003eeg1 data = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 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\u003e\u0026gt;\u0026gt;\u0026gt; output = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 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\u003eeg2 data = [1 3 6 7 9 ; 3 5 6 9 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u0026gt;\u0026gt; output = [1 3 6 7 9 ; 3 5 6 9 1; 2 4 6 8 5]\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":511,"title":"Converting Decimal to Binary","description":"Given a decimal number that may include a fractional component, convert it into binary representation. The numbers you are given will always be cleanly representable using positive and negative powers of 2.\r\n\r\nAs with \u003chttp://www.mathworks.com/help/techdoc/ref/dec2bin.html dec2bin\u003e, return your result in a string.\r\n\r\nExamples:\r\n\r\n Input  d = 2.5\r\n Output b is '10.1'\r\n\r\n Input  d = 34.125\r\n Output b is '100010.001'\r\n \r\n","description_html":"\u003cp\u003eGiven a decimal number that may include a fractional component, convert it into binary representation. The numbers you are given will always be cleanly representable using positive and negative powers of 2.\u003c/p\u003e\u003cp\u003eAs with \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/dec2bin.html\"\u003edec2bin\u003c/a\u003e, return your result in a string.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e Input  d = 2.5\r\n Output b is '10.1'\u003c/pre\u003e\u003cpre\u003e Input  d = 34.125\r\n Output b is '100010.001'\u003c/pre\u003e","function_template":"function b = dec2bin_fractions(d)\r\n  b = 0;\r\nend","test_suite":"%%\r\nd = 1;\r\nb = '1';\r\nassert(isequal(dec2bin_fractions(d),b))\r\n\r\n%%\r\nd = 2.5;\r\nb = '10.1';\r\nassert(isequal(dec2bin_fractions(d),b))\r\n\r\n%%\r\nd = 34.125; \r\nb = '100010.001';\r\nassert(isequal(dec2bin_fractions(d),b))\r\n\r\n%%\r\nd = 452.8125;\r\nb = '111000100.1101';\r\nassert(isequal(dec2bin_fractions(d),b))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":2591,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2012-03-20T18:00:02.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-03-20T14:21:56.000Z","updated_at":"2026-04-03T03:07:57.000Z","published_at":"2012-03-21T21:01: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\u003eGiven a decimal number that may include a fractional component, convert it into binary representation. The numbers you are given will always be cleanly representable using positive and negative powers of 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/dec2bin.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edec2bin\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, return your result in a string.\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  d = 2.5\\n Output b is '10.1'\\n\\n Input  d = 34.125\\n Output b is '100010.001']]\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":2413,"title":"Temperature Conversion Utility","description":"There are a few problems on Cody regarding temperature conversion (C to K, C to F, F to C), but none include Rankine. Furthermore, they each involve simple one-liner solutions. For this problem, you are to write a utility function that takes a given temperature and two capital letters designating which temperature scale is being converted to which. For example, T_convertor(100,'C','F') requires 100 degrees Celsius be converted to Fahrenheit.\r\n\r\nThe test suite includes all 16 possible combinations: C to F, C to R, C to C, C to K, K to F, K to R, etc. (Yes, the redundant combinations are included.)\r\n\r\nFor reference, temperature conversion formulas are available at \u003chttp://en.wikipedia.org/wiki/Temperature_conversion\u003e.\r\n\r\nA follow-on problem (more difficult with string inputs) is located here: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2415-temperature-conversion-utility-strings\u003e.","description_html":"\u003cp\u003eThere are a few problems on Cody regarding temperature conversion (C to K, C to F, F to C), but none include Rankine. Furthermore, they each involve simple one-liner solutions. For this problem, you are to write a utility function that takes a given temperature and two capital letters designating which temperature scale is being converted to which. For example, T_convertor(100,'C','F') requires 100 degrees Celsius be converted to Fahrenheit.\u003c/p\u003e\u003cp\u003eThe test suite includes all 16 possible combinations: C to F, C to R, C to C, C to K, K to F, K to R, etc. (Yes, the redundant combinations are included.)\u003c/p\u003e\u003cp\u003eFor reference, temperature conversion formulas are available at \u003ca href = \"http://en.wikipedia.org/wiki/Temperature_conversion\"\u003ehttp://en.wikipedia.org/wiki/Temperature_conversion\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eA follow-on problem (more difficult with string inputs) is located here: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2415-temperature-conversion-utility-strings\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/2415-temperature-conversion-utility-strings\u003c/a\u003e.\u003c/p\u003e","function_template":"function T_out = T_convertor(T,u1,u2)\r\n T_out = T;\r\nend","test_suite":"%%\r\nT = 100;\r\nu1 = 'C';\r\nu2 = 'F';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-212) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'C';\r\nu2 = 'R';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-671.67) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'C';\r\nu2 = 'C';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-100) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'C';\r\nu2 = 'K';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-373.15) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'K';\r\nu2 = 'F';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-(-279.67)) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'K';\r\nu2 = 'R';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-180) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'K';\r\nu2 = 'C';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-(-173.15)) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'K';\r\nu2 = 'K';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-100) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'F';\r\nu2 = 'F';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-100) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'F';\r\nu2 = 'R';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-559.67) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'F';\r\nu2 = 'C';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-37.7777778) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'F';\r\nu2 = 'K';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-310.9277778) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'R';\r\nu2 = 'F';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-(-359.67)) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'R';\r\nu2 = 'R';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-100) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'R';\r\nu2 = 'C';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-(-217.5944444)) \u003c eps)\r\n\r\n%%\r\nT = 100;\r\nu1 = 'R';\r\nu2 = 'K';\r\neps = 1e-4;\r\nassert(abs(T_convertor(T,u1,u2)-55.5555556) \u003c eps)\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":50,"test_suite_updated_at":"2014-07-11T12:34:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-07-11T12:30:22.000Z","updated_at":"2026-04-03T03:09:06.000Z","published_at":"2014-07-11T12:34:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are a few problems on Cody regarding temperature conversion (C to K, C to F, F to C), but none include Rankine. Furthermore, they each involve simple one-liner solutions. For this problem, you are to write a utility function that takes a given temperature and two capital letters designating which temperature scale is being converted to which. For example, T_convertor(100,'C','F') requires 100 degrees Celsius be converted to Fahrenheit.\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 test suite includes all 16 possible combinations: C to F, C to R, C to C, C to K, K to F, K to R, etc. (Yes, the redundant combinations are included.)\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 reference, temperature conversion formulas are available 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=\\\"http://en.wikipedia.org/wiki/Temperature_conversion\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Temperature_conversion\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA follow-on problem (more difficult with string inputs) is located here:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/2415-temperature-conversion-utility-strings\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/2415-temperature-conversion-utility-strings\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":2415,"title":"Temperature Conversion Utility (Strings)","description":"This is a follow-on problem to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2413-temperature-conversion-utility Problem 2413: Temperature Conversion Utility\u003e.\r\n\r\nYou are provided a cell array of strings that contains the source temperature and units (in various formats) and a separate cell array of strings that contains the target temperature units (in various formats). Produce a numerical vector of converted temperature values. \r\n\r\nExample:\r\n\r\n T_in  = {'100 Celsius', '50degF', '90K', strcat('111',char(176),'R')};  \r\n T_to  = {'R','C','degF','kelvin'}; \r\n T_out = [671.67 10 -297.67 61.6666667];\r\n\r\nFor reference, temperature conversion formulas are available on \u003chttp://en.wikipedia.org/wiki/Temperature_conversion Wikipedia\u003e.","description_html":"\u003cp\u003eThis is a follow-on problem to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2413-temperature-conversion-utility\"\u003eProblem 2413: Temperature Conversion Utility\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eYou are provided a cell array of strings that contains the source temperature and units (in various formats) and a separate cell array of strings that contains the target temperature units (in various formats). Produce a numerical vector of converted temperature values.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e T_in  = {'100 Celsius', '50degF', '90K', strcat('111',char(176),'R')};  \r\n T_to  = {'R','C','degF','kelvin'}; \r\n T_out = [671.67 10 -297.67 61.6666667];\u003c/pre\u003e\u003cp\u003eFor reference, temperature conversion formulas are available on \u003ca href = \"http://en.wikipedia.org/wiki/Temperature_conversion\"\u003eWikipedia\u003c/a\u003e.\u003c/p\u003e","function_template":"function [T_out] = T_convertor_str(T_in,T_to)\r\n T_out = 1;\r\nend","test_suite":"%%\r\nT_in = {'100 Celsius', '50degF', '90K', strcat('111',char(176),'R')};\r\nT_to = {'R','C','degF','kelvin'};\r\nT_out = [671.67 10 -297.67 61.6666667];\r\neps = 1e-3;\r\nassert(sum(abs(T_convertor_str(T_in,T_to)-T_out)) \u003c eps)\r\n\r\n%%\r\nT_in = {'10C','20degC','30 Celsius','40 Centigrade',strcat('50',char(176),'C'),'60K','70 kelvin','80 FAHRENHEIT'};\r\nT_to = {'R','R','Rankine','deg R','R','R',strcat(char(176),'R'),'degR'};\r\nT_out = [509.67 527.67 545.67 563.67 581.67 108 126 539.67];\r\neps = 1e-3;\r\nassert(sum(abs(T_convertor_str(T_in,T_to)-T_out)) \u003c eps)\r\n\r\n%%\r\nT_in = {'100 DEGREES RANKINE','100degC','100K','100F','1000R','1000 centigrade','1000 deg F','1000 kelvin'};\r\nT_to = {'C','degC',strcat(char(176),'C'),'Celsius','centigrade','deg C','degrees Celsius','CENTIGRADE'};\r\nT_out = [-217.5944444 100 -173.15 37.7777778 282.4055556 1000 537.7777778 726.85];\r\neps = 1e-3;\r\nassert(sum(abs(T_convertor_str(T_in,T_to)-T_out)) \u003c eps)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-07-11T18:21:42.000Z","updated_at":"2026-04-03T03:10:48.000Z","published_at":"2014-07-11T18:21:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a follow-on problem to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/2413-temperature-conversion-utility\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2413: Temperature Conversion Utility\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are provided a cell array of strings that contains the source temperature and units (in various formats) and a separate cell array of strings that contains the target temperature units (in various formats). Produce a numerical vector of converted temperature values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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[ T_in  = {'100 Celsius', '50degF', '90K', strcat('111',char(176),'R')};  \\n T_to  = {'R','C','degF','kelvin'}; \\n T_out = [671.67 10 -297.67 61.6666667];]]\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\u003eFor reference, temperature conversion formulas are available on\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Temperature_conversion\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eWikipedia\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":44274,"title":"Calculate the sum of two polynomials","description":"Calculate the sum of two polynomials if they are written in notation with their coefficients.\r\nexample:\r\n()  +  ()  =  \r\na=[3 4 5];\r\nb=[1 4 7 6];\r\n\r\noutput =[1 7 11 11];","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: 172.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 86.3667px; transform-origin: 407px 86.3667px; 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: 276.5px 8px; transform-origin: 276.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCalculate the sum of two polynomials if they are written in notation with their coefficients.\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: 28px 8px; transform-origin: 28px 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: 2.5px 8px; transform-origin: 2.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ4AAAAmCAYAAAA1HCJjAAAGA0lEQVR4Xu2bT+hmUxjHZ/YjhhUpZSxMFKVBZBqFKZGk/F8okz8LWRGzmCaJQllYzJAshFCyIEXTLGjk3xRFbCiaxgozZc/3U/eZnt/9nXvvufc9557L79z69t63997z53u+5znP85zzbt5Ur8pAAQY2F6izVlkZ2FSFV0VQhIEqvCK010qr8KoGijCwNOE9JxZuFi5s2HhXnw8LfxZhp1aajYElCe8d9fIM4TVhq/BoI8C/9XleFV82DRQpeCnC26HevyTc6AR2pu6/F84W9grPFmGoVpqFgaUIjyX2qIDV89fL+vKA8IrwYBYGaqG5GcCAMHZrDMeQ8B7SC7cKVwlbhN+Fz4S5/C4E+dh/0OJB9hHhXOG03CO7gPLRyYGedtzZNip9wsP63C78JJwULmrER/n4XZcKP2futLXhctXzdea6UhZvlhqeNoLwjqufuEShC2N1sbAmQOwSHsTtFHDwP3GlPan7Z5rvRJx3pBytQFl0CAubu56U3aCtbzcFbgThYe2eF/YIfwWIxDitM1Ah4W3Tgx8KV7dV2hT6sT5vEHKTSof2CdeEGj5BKRbAYL13T3g/5hW4+1Y4JpASys1RTJvsGfi8T/hUeHzMiwPPTjIOIeFh1XD0vaXzdZvfhQk9J2EHfFEW0UJUVzvGVs1kYdLkFMMXKh9hfyfgm+asa2z/bdzgM9XEM07X+XBDjRsKLkLvzxFp/qiK9wvtKHeoP32/5xYeA3uvgD/zxAYRHhPtioZ0JtnnwvvCwaGBmiI8TCtXqiWw3UbExnKVOm+XU3gs44eF2wQsilmX/7PFMz5DGqPfWPxOAY4VHqJgF+ERoS/KZKkkIr62ESgRDykYawi/E37zjF+yKf+E0M7Z0cnLVhRjLuGZW/CG2me+U6zw8AnhYJdgKasLdG/OuPmlWJVVg7nUSy1tv144X7jEtd8LsTP/Gis8KnlTgADUjGj6HFQGmW0vopz3BMsB4hNajosG2p4sZFPe3cJbAn6SXafrhv3bVS1sLuHZZLzStTlWeDj8vzSDZ3kwE5hZUQtUSGt1BXx+sLvuUwsvVI8FhD614g3OqXeGhMdgPdUIrl0RRGyP6LH5hDx6lgDBZtUQNELEmvUlIFM4xDmER+rkReEWwa8AscLz9OHXMhFNYCSg9wsIGxGSB1slbzqH8OiPX834HgxCh4TniWHg7hdYGuyK2cryeS2LUO9qiIzQbbJHUgvPUichX2aK8PwEhSci45Rpj7mEZwPmA491GwBjhGcFjk2QMgP+aF7OvePxTwKZxlpXiP1VCCW3pwjP8/qlyvUHJmK61efsx7xvz6Q6kIGV/qopdF2ZU4RHWbaVxX3MdpZfRmKW5zFE+WfnEp6dG+zyuaYIz0/QmJWkzdHShEf7bCstmfD87IwRngm1ZHoh5VI7ReAxfbeBirW6Yybo3EstbbPlNpnw/CAOHdJsz0Sy5ql2I8YQv3ThmTCsT1NXoy5OSgoviY9Hx8ziDc1Mlg/8IBxwi1rZUE7pNMeKL6Xwhuocu9TSNtJOHMCwQxipJ+jcwjPXYeWo1pPN0onzy4mEvm0tTK1tSpufh+NsOS/yPuSt5vhPxVKFZ5OTXY9vBAvE/ARl/3zVnZy5hdd7ljJkzu0UA5YqdODTDv2FLBeRDBc5LROkleHTBdRrh0znSq0sSXi0hZwcCXbyda87YbUnKDwyFquuEimFx4r3qsDGQGhHxZLfPzgj4w1X8A/dduyJB22X4lDzFrOSXQT+H9GegT585j0y7jc1BPO6D0gwv+xO+N/XNCzDl6UIz59phKePBD/B/QRNeeI7pfDaJ45tb5ZdmOsEDkt8IHT+XSFk8RDQ0wIDZRfZ9N8ETh50LY0kVDm0yXYJy+k9TnRWjkU5Xb9n0NupIpciPG8tSJsgRO9qeB5Dv0/lKKXwaAPis38CWpsYV6zzC0LvifHUkdNUUuZ4zzbcqcvvq85R9xLqMBeKHZHif5zaSMJbwuDXNjQMVOFVKRRhoAqvCO210iq8qoEiDFThFaG9VlqFVzVQhIEqvCK010qr8KoGijDwL4jkhzZeWdYCAAAAAElFTkSuQmCC\" style=\"width: 79px; height: 19px;\" width=\"79\" height=\"19\"\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: 17px 8px; transform-origin: 17px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)  +  (\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANkAAAAmCAYAAABJej66AAAHzUlEQVR4Xu2cS6h9UxzH//85eY1ICANKUZ4RYUCJJHnF4JbyKhmIMNDNAKEkA4+om0deGZgolAEpz6KIAUqJkVfM+X5O+5ffXXc/1t57rXXPuWft+nbOvXvtvdf6rd/3t36Ptc/+ffWoEqgSyCqB/VnvXm9eJVAlsK+SrCpBlUBmCVSSZRZwvX2VQCVZ1YEqgcwSyEGya9TnTeGEpu/v6vM64ffMY1ml2x+qzj4lnCscLvzT/H33Kg2i9jVOAqlJBsEeFx4QfhTuFC4SPhHOiuvSnm8FwT4SPhDeFE4V7hMOqHLam3OfmmQfS0zXCz84cf3SWOvD6mq2kMq9wjHCzU5Gp+v7p83fZ+jzs72pbus5qpQkw0If16IgEO8o4aRKsoWSvSPcFhgi/v+tgIt9rfDaeqrjyo4ab+3YBl+E85eSZG0Sgng/CXcJT6+YCM2tO1L9PrBA3zFGZwrLuJIRBrwaKQPiywtbjG3k5SvTDGLdKFwifCNsCe+1GM+sdTIL7pEak7RqxzPq8E0CSlOCZLjVHMu44rP6olQxx3dqdGJMwxVtg16/0sjjV32Sf+hdQHKtZMQdtwtkzjheXzGiectdgmS42d8Ltw5N2C4opvWNOXy+5/lY9auFR4W9miUldn6r0WuSeej4YPyci2TMBYy/R8BV5LhYIJ0/52CQTwp/Nfebc6+ua1GqL4WfBWKkEiQjBjtYSFXquEX32hDIYM5VeFZ0+jbkjRBT4lovg6tIn08WyHSnim9NL8gCs4JRfvEJvk5dzEkyeyir2oNCCguHy4LrklPxiY0g8VcCBiLns5ARY3pCuDR20jpn8/8TjzR9x6hh3OYcKCxz2FfntNVuWVxFi28pjTw0Z/DuWktMoQ9XCtELRgmS0c9/hWcFn7aeMvbcJEM5bxCIi2wVzkkylPNDIdoqRgotJcliHmmGNMUcxzxvqE1qkpk8ee5ow1WSZCnijZwkwxV931kpE2wukuFOvy3cP8YqDmlXc740yczKpwgJIofY2yw1yf7W03ATOUaPsY9kKAGB7AWNpSWJ4Yli2UPa4KMe0TFsiMHOhlOEKB+2R3y5SMZYvhZeEiyGiSUZqxEyOF84u5mM491YLY4kPW8JICsPbOp/YczAc98QBgPqHjmVJJm5in06QFeRw1XCeQKyCNvbbqFQz3qG2XkqJcmIb9kCx2GuIjuZbK4ZB97IY11z1kcyFPoQ4Q8BkljAB5lMSXiw7VG8Qt9fFLDOkBEf3tq9oO8pfONcJEPRjxb81q9YkjEJbCGjGGmTYWSy1dGSKMQs5whsqzpIgNT+oA+A2sucvZ4lSRbrKtKOQi3xDKURDjPayJCYnRUDks3NRqckGbqBEeWAZMwlCSXidubKznG+dSNBrLtoNSNuxPYolOlPgRgLSwaZUIqXBawUB4KizXPCHKvc3G7xkYNkZkEvD/oZSzLfP3ObPJk21YCJgnDIiCSQnxh/Pd9TBOslSTbWVURXfmsGTQyHfpAWt7iUOf68kVUom9i/U5LM7mU6bQuI9cUMqbmTOzYTxJLM140sq5Iq3RwruBwks7Rs246UKSTzxgg5kaGcm0IfIx9rW4pksa5iOAYjJq4WK8IdQnS2LkIgKUlG0o6jbyeLdyl3rMKxJPPWh4eliK+6ZGWDipBlZ5PYDBCTwbavthrQFJJ5Y0Sxcq7b1zVAW9HnyIhr566asa5i2E9vjKZkJH22b44MYraweZJ17fwJ+bGtXSzJGIh3hXJumylFMibqMoEYqS3+mUKy0BWaW7JYdpKNdRVtPN4YTdkQvWwk8/zg+zbyjiGZBYC5UtoxFillTDaFzDFjt1d7YlfTmHGPbVPCXZzqKjIWuzbFatomm5Tuot1raO597DaJZKF7MrpWMFZLOtovO8lCCzvGiCUS0eI2JUhmLt8Ud88rZI4XelOSzGcX+9xLT8Zt4VSMEvjXVSxFnWKL1BSlSkmyoeePdRetHkj2EHDsljEqQTJbsceOkb5RKyMWtixrjB4OzZc/n5Jksa6tT+ZsqxnHDI4O20ZTu5G3PmRWyKjMqevECnBZSWaGiBoQ6WdLUXtjRJIgRa0wRla5SWZvcg+5UGFfmb8tgXT9aYK9o2ZExY3k/3M39aYkGWOICQEs/NixALWRDAFyUNuywVptwGeFuBaCUYQulc5fJpLRF3awUKynuOwL7qExQo5Y7lLp/NwkMz0YKhpjfCANhgcCUQ/bEIhXfZIIxXy4kWOKdH5qklkWFV60uYyWwqckseN9wJBk/rcmrLrtd4f7pdNqHCl3jzf87vxYFpJ5oSMnv8uFzntjZNtuwiLm0FjnnM9NMrPsQ5lB/7IncsKN9qu5GSPGipx4jSnFap+aZPTPJ/58zGXFaHarhBsaFnMYksx2hbO1BZcw/FEcrrEBdJ2foxxD1y4LyTA27FSgyk/gH74K4uXYdn5onHPP5ySZdxXZVtQXJvi4NiQYYzQ58r3t/FQ55CAZfUH/bN8i26sopHMQTrESt8oiJiabOtAc19lmW+5df2KuW8K4LxsCO05y1epyzG+qe9pLm1u64a7/tsyqkSzVJNT7VAkUk0AlWTFR1wetqwQqydZ15uu4i0mgkqyYqOuD1lUClWTrOvN13MUkUElWTNT1QesqgUqydZ35Ou5iEqgkKybq+qB1lcB/7fUTRXCC8XIAAAAASUVORK5CYII=\" style=\"width: 108.5px; height: 19px;\" width=\"108.5\" height=\"19\"\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: 14.5px 8px; transform-origin: 14.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)  =  \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPcAAAAmCAYAAAAY7g3ZAAAHHUlEQVR4Xu2cOagtRRCGz8sVt0gDFTVQEBRcURQ1UBBFRNyTF4gbiIEoPgO5GKhoIGLggsHDBVwwMBE0MFAEV9BIAxUU0cgNzfX/HlPQjjPndE93zz23pwaKe+453TPd/9RfXV1VM/tWfjgCjkCTCOxrclY+KUfAEVg5uV0JHIFGEXByN3pjfVqOgJPbdcARaBSBGuS+UVjtSE7tMHtPf2+W/NYohlOmdbQ6PSu5SHKs5O/u/wemnMz7OAJDCJQmN8R+SvKI5HvJfZLLJZ9IzvdbcAgBiP2R5APJW5KzJA9JDnOcXENKIlCa3B9rcLdKvgsG+XO3Oh2jv756r1YHhMOJkjsCjM7R50+7/8/V389K3mQ/1zIRKEluVqSTBxQTwh8vOd3JfUjJ3pXc3TOAfP+1hK3MTZLXl6mOPuuSCJQk99C4IPwPkvslz5UceKFzMb5fE851V8V5YATPk+yVlRtD/qjkSMkVCRjSNKdv4qW2svmdGtXDkmskqV5adN+a5LagEeiyF9/GAxcZBY05CHqdKQm3HDH9YtuwfeHYdg/HiHlDN14CprHkzukbi+M2tzNiEkTlSDHkyX1rkRvS3COxSbyxpQSHUD9KCAL+PqIVBLwwADWDgij9t5KankEJpee+YuBYrQmUcsSSO6dvibHv5jmIqdzWDeAW/SV4GkvuyX1rkZuBs3I/KMEl58C6owg5BxN9RvJnd76cc1nK7kKdZF2g73n9frukJvHYY0OYUilDrPx+CRH5kuk1jJB5Lv904MeSO6dvzn1O7cv9PkOCwS8V+wjn/kTAiZiVe3LfmuQ2UM31fbKAorFaEJDCRT489a712kMA0nWbDA6rO9eq5ZIzp6clVwXEyZzayhQolnhTrpdK7vAaOX2njDWlj8U+SE8+ltIxsm0qucPTJvWdg9wMjpv5giRM/0Ri8Z9mJckdc31LUX2jxqfFdEhsg1X+UEIxS8m9vJM78UYEzZ3cidhB7hJu7dzkNpe8hNfRh4xtyzsSoqabvIdEuH3lTgVsaeRG+YiIXtqtLATHQoJaNJw2v0iOGwEUQlKJVcKtnZvc5pJfpvGPpSxYfcHgEskFEoIlpwQrscUJSHNZYNGq1Hb0XX9fx6r75prrxehtays3GF4vuVgCjn19s8rIvo7GYNVvs4iVGyIdJSGKDDlRWgPVlBNgrIb8Wn1+WcJqhBEgSGXtXtLnEvuXOckd65Lb3v0kzZF6cQ4jMed4X/JThxPuPQE8yk+PkLzS06wT9D9yZYffFOWkT2vkJm7zheQ6CcFNDltowB/P6i8J5M7NzCyC3KFimXvKd5SRosR/SNhDs3JBYsj8qgTLygHItHlRkpqoD68dfp6T3FNccqsyC0m8owmwOkN0MCKtZjnioXmWCOS0Rm7DKSw6IoaDbr0tsZgF+vF5h/OYDm36fnHkxu15rUPF9oel0jabwN4tcse45P2xh0YQnL6SlExFxWLVKrmZvxlQvEhSovdKSsYsFkfu0GLWrtSyNEmsIg+1y00Bxbrk/WuHRpCil1z3egwD82ByMKJvjpeQk87K6Rsa0CkZmDCdlINfTI566PxJ6azeCZL6pqTCQpezRlrI5rEN5J7ikjP+vtuYm/pzcv8fgdCATnnIxsk9oFXsG9krliggmWox59pzT3HJbU72iGuu9zAVI/q17JZbqW6u5zGG7+Lc8r4bWKKUdIryzkFuWxmmFK70V4UUz2gKHmN9Wia3kY+516j3XxS5w8c2LdVTo6gjRrnnILd5KKlztHw+0XB70my3jGCr5GZe5Lp5jNgyDqUN6KLIzWTtAQTbd4cWkzwjaa853rIyB7nJl5LTTwmYmAEkD0sqxp4RDw0EudoSuf4YI9giubn3ByWkvc6WWPbGDCjuOt/nPuzRNLmJFHOQmzagrCgljFRiMSE2xStzpcVqk9tc8nUVd0YuxkI9OEU+FKWEhTp9IwiOrDZzpcVaIDcGE7JiLCEu+ez9EmIZYeASA/p4dw9KpMWaJXf4Li8CZ1RWhU8rhZFKyzOWfJrJiDP2tza5zSXflGIJX/IATmFVHmMPjSA48XCIGchNcyzxe21yhzGY1NhEbF+e/qMtBxiz1Qk9HzOg/A7GPApcwjOqTe4wZpAa7U/q29+v2FNKlPHhevdfdgiQdoGx30so526R21zyTXtljBzVUbjvGALIHm5LQhyHfq+JEeeuRW7z1Ix0Ng/IRSntupr41L42hyFic127B3zuEz8H3xrkRh/w2q6W2AtMbIxsab9cY5gm9y0djMgBNaavPYRBW39V8jhi9rIGKuRq5dpj7tdebGMvaziowW/je/+iMd1r5I6emDd0BJaOgJN76Rrg828WASd3s7fWJ7Z0BJzcS9cAn3+zCDi5m721PrGlI+DkXroG+PybRcDJ3eyt9YktHQEn99I1wOffLAL/AqwXL0WK9YJJAAAAAElFTkSuQmCC\" style=\"width: 123.5px; height: 19px;\" width=\"123.5\" height=\"19\"\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: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ea=[3 4 5];\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; \"\u003eb=[1 4 7 6];\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: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\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: 80px 8.5px; tab-size: 4; transform-origin: 80px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eoutput =[1 7 11 11];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function p = rwpadd(a,b)\r\n  p= a+b;\r\nend","test_suite":"%%\r\na=[3 4 5];\r\nb=[1 4 7 6];\r\ny_correct = [1 7 11 11];\r\nassert(isequal(rwpadd(a,b),y_correct))\r\n\r\n%%\r\na=[1 1 1 3 -2];\r\nb=[1 3];\r\ny_correct = [1 1 1 4 1];\r\nassert(isequal(rwpadd(a,b),y_correct))\r\n\r\n%%\r\na=[1];\r\nb=[1 2 3];\r\ny_correct = [1 2 4];\r\nassert(isequal(rwpadd(a,b),y_correct))\r\n\r\n%%\r\na=randi(10,1,5);\r\nb=[];\r\nassert(isequal(rwpadd(a,b),a))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":38144,"edited_by":223089,"edited_at":"2022-12-12T05:56:48.000Z","deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":"2022-12-12T05:56:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-02T18:19:55.000Z","updated_at":"2026-04-03T03:11:51.000Z","published_at":"2017-08-02T18:19:55.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\u003eCalculate the sum of two polynomials if they are written in notation with their coefficients.\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\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e3x^2+4x+5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e)  +  (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ex^3+4x^2+7x+6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e)  =  \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ex^3+7x^2+11x+11\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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=[3 4 5];\\nb=[1 4 7 6];\\n\\noutput =[1 7 11 11];]]\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":1344,"title":"Moving average (variable kernel length)","description":"Find the moving average in a vector. The kernel length is a variable.\r\nFor example \r\n\r\n x = 1:10\r\n kernel_length = 2 \r\n\r\nwould result in\r\n\r\n [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]\r\n\r\nand\r\n\r\n x = 1:10\r\n kernel_length = 3 \r\n\r\nwould result in\r\n\r\n [ 2 3 4 5 6 7 8 9 ]\r\n","description_html":"\u003cp\u003eFind the moving average in a vector. The kernel length is a variable.\r\nFor example\u003c/p\u003e\u003cpre\u003e x = 1:10\r\n kernel_length = 2 \u003c/pre\u003e\u003cp\u003ewould result in\u003c/p\u003e\u003cpre\u003e [ 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 ]\u003c/pre\u003e\u003cp\u003eand\u003c/p\u003e\u003cpre\u003e x = 1:10\r\n kernel_length = 3 \u003c/pre\u003e\u003cp\u003ewould result in\u003c/p\u003e\u003cpre\u003e [ 2 3 4 5 6 7 8 9 ]\u003c/pre\u003e","function_template":"function y = moving_avg(x,kernel_length)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1:10;\r\nkernel_length=4\r\ny_correct = [  2.5000    3.5000    4.5000    5.5000    6.5000    7.5000    8.5000];\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n%%\r\n\r\nx = 10:20;\r\nkernel_length=5\r\ny_correct = [  12.0000   13.0000   14.0000   15.0000   16.0000   17.0000   18.0000];\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n%%\r\nx = ones(1,10);\r\nkernel_length=5\r\ny_correct = ones(1,6);\r\nassert(isequal(moving_avg(x,kernel_length),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1023,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-15T03:02:53.000Z","updated_at":"2026-04-03T03:14:22.000Z","published_at":"2013-03-15T03:02:52.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the moving average in a vector. The kernel length is a variable. For example\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = 1:10\\n kernel_length = 2]]\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\u003ewould result in\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.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.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\u003eand\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:10\\n kernel_length = 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\u003ewould result in\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[ [ 2 3 4 5 6 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":44156,"title":"Weighted average","description":"Compute the weighted average Y, of the vector A, given the weight vector W.\r\n\r\nThe weighted average is the sum of the dot product of A and W, normalized by the sum of W.\r\n\r\nExample 1:\r\n\r\n  A = [10 15 20 10];\r\n  W = [ 1  1  1  1];\r\n  Y = 13.75\r\n\r\nExample 2:\r\n\r\n  A = [  10    15   20   10];\r\n  W = [0.25  0.25 0.25 0.25];\r\n  Y = 13.75\r\n\r\nExample 3:\r\n\r\n  A = [10 15 20 10];\r\n  W = [ 2  4  4  2];\r\n  Y = 15","description_html":"\u003cp\u003eCompute the weighted average Y, of the vector A, given the weight vector W.\u003c/p\u003e\u003cp\u003eThe weighted average is the sum of the dot product of A and W, normalized by the sum of W.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [10 15 20 10];\r\nW = [ 1  1  1  1];\r\nY = 13.75\r\n\u003c/pre\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [  10    15   20   10];\r\nW = [0.25  0.25 0.25 0.25];\r\nY = 13.75\r\n\u003c/pre\u003e\u003cp\u003eExample 3:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [10 15 20 10];\r\nW = [ 2  4  4  2];\r\nY = 15\r\n\u003c/pre\u003e","function_template":"function Y = weighted_average(A,W)\r\n  Y = A;\r\nend","test_suite":"%%\r\nA = [10 15 20 10];\r\nW = [ 1  1  1  1];\r\nY = 13.75\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nA = [  10    15   20   10];\r\nW = [0.25  0.25 0.25 0.25];\r\nY = 13.75\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nA = [10 15 20 10];\r\nW = [ 2  4  4  2];\r\nY = 15\r\nassert(isequal(weighted_average(A,W),Y))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'regexp')))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'feval')))\r\n\r\n%%\r\nassert(~any(strfind(lower(fileread('weighted_average.m')),'eval')))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":130819,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":118,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-05-04T14:38:26.000Z","updated_at":"2026-04-03T03:15:25.000Z","published_at":"2017-05-04T14:38: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\u003eCompute the weighted average Y, of the vector A, given the weight vector W.\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 weighted average is the sum of the dot product of A and W, normalized by the sum of W.\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 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[A = [10 15 20 10];\\nW = [ 1  1  1  1];\\nY = 13.75]]\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\u003eExample 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[A = [  10    15   20   10];\\nW = [0.25  0.25 0.25 0.25];\\nY = 13.75]]\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\u003eExample 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[A = [10 15 20 10];\\nW = [ 2  4  4  2];\\nY = 15]]\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\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}