{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":44401,"title":"Vertical matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 8  9  3  9\r\n      9  6  5  2\r\n      2  1  9  9\r\n  \r\n  y = 2  1  3  2\r\n      8  6  5  9\r\n      9  9  9  9\r\n      9  9  9  9\r\n      8  6  5  9\r\n      2  1  3  2","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 8  9  3  9\r\n    9  6  5  2\r\n    2  1  9  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 2  1  3  2\r\n    8  6  5  9\r\n    9  9  9  9\r\n    9  9  9  9\r\n    8  6  5  9\r\n    2  1  3  2\r\n\u003c/pre\u003e","function_template":"function y = upAndDown(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0;0];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = zeros(10);\r\nx(7,4) = 1;\r\ny_correct = zeros(20,10);\r\ny_correct(10:11,4) = [1;1];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 4 3 2; 1 4 3 2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [8  9  3  9; 9  6  5  2; 2  1  9  9];\r\ny_correct = [2  1  3  2; 8  6  5  9; 9  9  9  9;\r\n             9  9  9  9; 8  6  5  9; 2  1  3  2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x; x];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x; flipud(x)];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nc = [1:3,3:-1:1]';\r\ny_correct = [c,c+3,c+6];\r\nassert(isequal(upAndDown(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":340,"test_suite_updated_at":"2018-05-13T07:02:36.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-11-12T07:18:04.000Z","updated_at":"2026-02-11T19:50:48.000Z","published_at":"2017-11-12T07:31:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x = 8  9  3  9\\n    9  6  5  2\\n    2  1  9  9\\n\\ny = 2  1  3  2\\n    8  6  5  9\\n    9  9  9  9\\n    9  9  9  9\\n    8  6  5  9\\n    2  1  3  2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44447,"title":"Eye Squared","description":"For a positive integer |n| create the identity matrix with |n| elements.\r\n\r\nIn case it is not possible to produce an identity matrix with exactly |n| elements, return an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n = 9\r\n  Output: I = [1 0 0\r\n               0 1 0\r\n               0 0 1]\r\n\r\n  Input:  n = 8\r\n  Output: I = []","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e create the identity matrix with \u003ctt\u003en\u003c/tt\u003e elements.\u003c/p\u003e\u003cp\u003eIn case it is not possible to produce an identity matrix with exactly \u003ctt\u003en\u003c/tt\u003e elements, return an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 9\r\nOutput: I = [1 0 0\r\n             0 1 0\r\n             0 0 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 8\r\nOutput: I = []\r\n\u003c/pre\u003e","function_template":"function I = eyeSquared(n)\r\n    I = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('eyeSquared.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 1;\r\nI_correct = 1;\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4;\r\nI_correct = [1 0; 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 9;\r\nI_correct = [1 0 0; 0 1 0; 0 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = -9;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 10;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4.1;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":234,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-11T00:36:01.000Z","updated_at":"2026-03-11T16:59:00.000Z","published_at":"2017-12-11T00:36:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e create the identity matrix with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn case it is not possible to produce an identity matrix with exactly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements, return an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n = 9\\nOutput: I = [1 0 0\\n             0 1 0\\n             0 0 1]\\n\\nInput:  n = 8\\nOutput: I = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44392,"title":"Sum of Two Numbers","description":"Given two integer numbers x and y, calculate their sum and put it in z.\r\n\r\nExamples:\r\n\r\n  Inputs x = 2, y = 4\r\n  Output z is 6\r\n\r\n  Inputs x = 1, y = -4\r\n  Output z is -3","description_html":"\u003cp\u003eGiven two integer numbers x and y, calculate their sum and put it in z.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInputs x = 2, y = 4\r\nOutput z is 6\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInputs x = 1, y = -4\r\nOutput z is -3\r\n\u003c/pre\u003e","function_template":"function z = sumTwo(x, y)\r\n  z = x * y;\r\nend","test_suite":"%%\r\nx = 1; y = 2;\r\nz_correct = 3;\r\nassert(isequal(sumTwo(x,y),z_correct));\r\n\r\n%%\r\nx = -21; y = 32;\r\nz_correct = 11;\r\nassert(isequal(sumTwo(x,y),z_correct));\r\n\r\n%%\r\nx = randi(100); y = randi(100);\r\nz_correct = sqrt(x^2 + y^2 + 2*x*y);\r\nassert(isequal(sumTwo(x,y),z_correct));\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":3,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":782,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-10-29T12:44:25.000Z","updated_at":"2026-02-24T00:51:23.000Z","published_at":"2017-10-29T12:44:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two integer numbers x and y, calculate their sum and put it in z.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Inputs x = 2, y = 4\\nOutput z is 6\\n\\nInputs x = 1, y = -4\\nOutput z is -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":44445,"title":"Tax Calculator","description":"Calculate the tax for a given income.\r\n\r\n10% tax is paid for any income up to $2,000.\r\n\r\n20% tax is paid for additional income up to $3,000.\r\n\r\n30% tax is paid for any additional income over $3,000.\r\n\r\nFor example, the tax for an income of $2,500 is calculated as follows:\r\n\r\n  $2,000 * 10% + $500 * 20% = $300","description_html":"\u003cp\u003eCalculate the tax for a given income.\u003c/p\u003e\u003cp\u003e10% tax is paid for any income up to $2,000.\u003c/p\u003e\u003cp\u003e20% tax is paid for additional income up to $3,000.\u003c/p\u003e\u003cp\u003e30% tax is paid for any additional income over $3,000.\u003c/p\u003e\u003cp\u003eFor example, the tax for an income of $2,500 is calculated as follows:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e$2,000 * 10% + $500 * 20% = $300\r\n\u003c/pre\u003e","function_template":"function tax = taxFor(income)\r\n  tax = income / 10;\r\nend","test_suite":"%%\r\nincome = 0;\r\ntax_correct = 0;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 100;\r\ntax_correct = 10;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 1000;\r\ntax_correct = 100;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 2000;\r\ntax_correct = 200;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 2500;\r\ntax_correct = 300;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 3000;\r\ntax_correct = 400;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 5000;\r\ntax_correct = 1000;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nfiletext = fileread('taxFor.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":215,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-10T23:09:53.000Z","updated_at":"2026-03-11T08:23:52.000Z","published_at":"2017-12-10T23:09:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCalculate the tax for a given income.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003e10% tax is paid for any income up to $2,000.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003e20% tax is paid for additional income up to $3,000.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003e30% tax is paid for any additional income over $3,000.\u003c/w:t\u003e\u003c/w:r\u003e\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 tax for an income of $2,500 is calculated as follows:\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,000 * 10% + $500 * 20% = $300]]\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":44437,"title":"How many days in a month?","description":"Return the number of days in a given month in 2017. If the input is not a valid month number, return -1.\r\n\r\nExamples:\r\n\r\n  Input: m = 1\r\n  Outpu: d = 31\r\n\r\n  Input:  m = 2\r\n  Output: d = 28\r\n\r\n  Input:  m = 13\r\n  Output: d = -1\r\n\r\nYou *cannot* use IF statements","description_html":"\u003cp\u003eReturn the number of days in a given month in 2017. If the input is not a valid month number, return -1.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput: m = 1\r\nOutpu: d = 31\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  m = 2\r\nOutput: d = 28\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  m = 13\r\nOutput: d = -1\r\n\u003c/pre\u003e\u003cp\u003eYou \u003cb\u003ecannot\u003c/b\u003e use IF statements\u003c/p\u003e","function_template":"function d = daysInMonth(m)\r\n  d = 31;\r\nend","test_suite":"%%\r\nfiletext = fileread('daysInMonth.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\nassert(isempty(strfind(filetext, 'if')),'IF statements are forbidden')\r\n\r\n%%\r\nm = 1;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 2;\r\nd_correct = 28;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 3;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 4;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 5;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 6;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 7;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 8;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 9;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 10;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 11;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 12;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 13;\r\nd_correct = -1;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = randi([-100 0]);\r\nd_correct = -1;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\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":495,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T20:28:10.000Z","updated_at":"2026-04-02T12:47:30.000Z","published_at":"2017-12-03T20:28: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\u003eReturn the number of days in a given month in 2017. If the input is not a valid month number, return -1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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: m = 1\\nOutpu: d = 31\\n\\nInput:  m = 2\\nOutput: d = 28\\n\\nInput:  m = 13\\nOutput: d = -1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecannot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use IF statements\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44402,"title":"Horizontal matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 9  2  8  1\r\n      5  4  9  8\r\n      8  9  6  9\r\n  \r\n  y = 1  2  8  9  9  8  2  1\r\n      4  5  8  9  9  8  5  4\r\n      6  8  9  9  9  9  8  6","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 9  2  8  1\r\n    5  4  9  8\r\n    8  9  6  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 1  2  8  9  9  8  2  1\r\n    4  5  8  9  9  8  5  4\r\n    6  8  9  9  9  9  8  6\r\n\u003c/pre\u003e","function_template":"function y = backAndforth(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0 0];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = zeros(100);\r\nx(41,68) = 1;\r\ny_correct = zeros(100,200);\r\ny_correct(41,100:101) = [1,1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 2 3 4 4 3 2 1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x,fliplr(x)];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x,x];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1; 4; 3; 2];\r\ny_correct = [1 1; 4 4; 3 3; 2 2];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [9  2  8  1; 5  4  9  8; 8  9  6  9];\r\ny_correct = [1  2  8  9  9  8  2  1;\r\n             4  5  8  9  9  8  5  4;\r\n             6  8  9  9  9  9  8  6];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nr = [1:3:7,7:-3:1];\r\ny_correct = [r;r+1;r+2];\r\nassert(isequal(backAndforth(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":"2018-01-02T21:54:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-12T07:54:27.000Z","updated_at":"2026-03-29T20:13:01.000Z","published_at":"2017-11-12T07:59:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x = 9  2  8  1\\n    5  4  9  8\\n    8  9  6  9\\n\\ny = 1  2  8  9  9  8  2  1\\n    4  5  8  9  9  8  5  4\\n    6  8  9  9  9  9  8  6]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44439,"title":"Remove the air bubbles from a vector","description":"_*A reduced version of Problem 112*_\r\n\r\nGiven a column vector v, return a vector w in which all the zeros have \"bubbled\" to the top. The order of the remaining nonzero numbers in the vector should be preserved.\r\n\r\nExample:\r\n\r\n  Input  v = [1\r\n              3\r\n              0\r\n              5\r\n              0\r\n              -1]\r\n\r\n  Output w = [0\r\n              0\r\n              1\r\n              3\r\n              5\r\n              -1]","description_html":"\u003cp\u003e\u003ci\u003e\u003cb\u003eA reduced version of Problem 112\u003c/b\u003e\u003c/i\u003e\u003c/p\u003e\u003cp\u003eGiven a column vector v, return a vector w in which all the zeros have \"bubbled\" to the top. The order of the remaining nonzero numbers in the vector should be preserved.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput  v = [1\r\n            3\r\n            0\r\n            5\r\n            0\r\n            -1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput w = [0\r\n            0\r\n            1\r\n            3\r\n            5\r\n            -1]\r\n\u003c/pre\u003e","function_template":"function w = bubbles(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('bubbles.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1 3 0 5 0 -1]';\r\nw_correct = [0 0 1 3 5 -1]';\r\nassert(isequal(bubbles(v),w_correct))\r\n\r\n%%\r\nv = [0 0 9 2 6]';\r\nw_correct = v;\r\nassert(isequal(bubbles(v),w_correct))\r\n\r\n%%\r\nv = [1 3 5 -1]';\r\nw_correct = v;\r\nassert(isequal(bubbles(v),w_correct))\r\n\r\n%%\r\nv = [0 1 0 1 1 1 0]';\r\nw_correct = [0 0 0 1 1 1 1]';\r\nassert(isequal(bubbles(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":193,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T21:41:30.000Z","updated_at":"2026-03-30T19:08:33.000Z","published_at":"2017-12-03T21:41: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\",\"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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA reduced version of Problem 112\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a column vector v, return a vector w in which all the zeros have \\\"bubbled\\\" to the top. The order of the remaining nonzero numbers in the vector should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\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  v = [1\\n            3\\n            0\\n            5\\n            0\\n            -1]\\n\\nOutput w = [0\\n            0\\n            1\\n            3\\n            5\\n            -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":44436,"title":"Find the largest number","description":"Find the largest number |x| among 4 numbers given as variables |a|, |b|, |c|, and |d|.\r\n\r\nExample:\r\n\r\n  Input:  a = 4; b = 7; c = 1; d = 6;\r\n  Output: x = 7;\r\n\r\nYou must *NOT* use MATLAB built in functions such as min(), max() or sort()","description_html":"\u003cp\u003eFind the largest number \u003ctt\u003ex\u003c/tt\u003e among 4 numbers given as variables \u003ctt\u003ea\u003c/tt\u003e, \u003ctt\u003eb\u003c/tt\u003e, \u003ctt\u003ec\u003c/tt\u003e, and \u003ctt\u003ed\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  a = 4; b = 7; c = 1; d = 6;\r\nOutput: x = 7;\r\n\u003c/pre\u003e\u003cp\u003eYou must \u003cb\u003eNOT\u003c/b\u003e use MATLAB built in functions such as min(), max() or sort()\u003c/p\u003e","function_template":"function x = largest(a, b, c, d)\r\n  x = a;\r\nend","test_suite":"%%\r\nfiletext = fileread('largest.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\nassert(isempty(strfind(filetext, 'max')),'max() forbidden')\r\nassert(isempty(strfind(filetext, 'min')),'min() forbidden')\r\nassert(isempty(strfind(filetext, 'sort')),'sort() forbidden')\r\nassert(isempty(strfind(filetext, 'unique')),'unique() forbidden')\r\n\r\n%%\r\na = 4; b = 7; c = 1; d = 6;\r\nx_correct = 7;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 1; d = 1;\r\nx_correct = 1;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 4; b = 3; c = 2; d = 1;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 2; c = 3; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 3; d = 5;\r\nx_correct = 5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 2; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 2; b = 3; c = 1; d = 6.5;\r\nx_correct = 6.5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 5; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 9; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 1; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":504,"test_suite_updated_at":"2020-05-13T19:39:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T12:39:01.000Z","updated_at":"2026-02-08T06:30:02.000Z","published_at":"2017-12-03T12:39:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the largest number\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw: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 among 4 numbers given as variables\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\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ed\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\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:  a = 4; b = 7; c = 1; d = 6;\\nOutput: x = 7;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou must\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNOT\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use MATLAB built in functions such as min(), max() or sort()\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":44415,"title":"Remove the first, third and fifth rows of a matrix","description":"Given a matrix x with at least five rows, return a matrix y that includes all rows of x except for th 1st, the 3rd and 5th.\r\n\r\nExample:\r\n \r\n Input:\r\n x = [1 1 1;\r\n      2 2 2;\r\n      3 3 3;\r\n      4 4 4;\r\n      5 5 5;\r\n      6 6 6]\r\n\r\n Output:\r\n y = [2 2 2;\r\n      4 4 4;\r\n      6 6 6]","description_html":"\u003cp\u003eGiven a matrix x with at least five rows, return a matrix y that includes all rows of x except for th 1st, the 3rd and 5th.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input:\r\n x = [1 1 1;\r\n      2 2 2;\r\n      3 3 3;\r\n      4 4 4;\r\n      5 5 5;\r\n      6 6 6]\u003c/pre\u003e\u003cpre\u003e Output:\r\n y = [2 2 2;\r\n      4 4 4;\r\n      6 6 6]\u003c/pre\u003e","function_template":"function y = deleteThreeRows(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 1 1;\r\n     2 2 2;\r\n     3 3 3;\r\n     4 4 4;\r\n     5 5 5;\r\n     6 6 6];\r\ny_correct = [2 2 2;\r\n             4 4 4;\r\n             6 6 6];\r\nassert(isequal(deleteThreeRows(x),y_correct))\r\n\r\n%%\r\nx = (1:5)';\r\ny_correct = [2;4];\r\nassert(isequal(deleteThreeRows(x),y_correct))\r\n\r\n%%\r\nx = ones(8);\r\ny_correct = ones(5, 8);\r\nassert(isequal(deleteThreeRows(x),y_correct))","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":596,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-26T22:27:53.000Z","updated_at":"2026-02-05T19:42:12.000Z","published_at":"2017-11-26T22:27:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x with at least five rows, return a matrix y that includes all rows of x except for th 1st, the 3rd and 5th.\u003c/w:t\u003e\u003c/w:r\u003e\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:\\n x = [1 1 1;\\n      2 2 2;\\n      3 3 3;\\n      4 4 4;\\n      5 5 5;\\n      6 6 6]\\n\\n Output:\\n y = [2 2 2;\\n      4 4 4;\\n      6 6 6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44446,"title":"Add a vector to a matrix","description":"Given a matrix |mat| of size |mXn| and a row vector |v| of size |1Xs|, return a matrix with |m+1| rows that conatains |mat| over |v|.\r\nThe number of columns is the larger between |n| and |s|.\r\n\r\nIf |s\u003en|, the matrix is padded with |Inf|.\r\n\r\nIf |n\u003es|, the vector is padded with |-Inf|.\r\n\r\nExamples:\r\n\r\n  inputs:\r\n  mat = [1  2\r\n         3  4]\r\n  v   = [5  6  7  8]\r\n\r\n  output:\r\n  comb = [1   2   Inf  Inf\r\n          3   4   Inf  Inf\r\n          5   6   7    8  ]\r\n\r\n  inputs:\r\n  mat = [1   2   3   4   5\r\n         6   7   8   9   10]\r\n  v   = [11  12]\r\n\r\n  output:\r\n  comb = [1    2     3     4     5\r\n          6    7     8     9     10\r\n          11   12   -Inf  -Inf  -Inf]","description_html":"\u003cp\u003eGiven a matrix \u003ctt\u003emat\u003c/tt\u003e of size \u003ctt\u003emXn\u003c/tt\u003e and a row vector \u003ctt\u003ev\u003c/tt\u003e of size \u003ctt\u003e1Xs\u003c/tt\u003e, return a matrix with \u003ctt\u003em+1\u003c/tt\u003e rows that conatains \u003ctt\u003emat\u003c/tt\u003e over \u003ctt\u003ev\u003c/tt\u003e.\r\nThe number of columns is the larger between \u003ctt\u003en\u003c/tt\u003e and \u003ctt\u003es\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003es\u0026gt;n\u003c/tt\u003e, the matrix is padded with \u003ctt\u003eInf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003en\u0026gt;s\u003c/tt\u003e, the vector is padded with \u003ctt\u003e-Inf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1  2\r\n       3  4]\r\nv   = [5  6  7  8]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1   2   Inf  Inf\r\n        3   4   Inf  Inf\r\n        5   6   7    8  ]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1   2   3   4   5\r\n       6   7   8   9   10]\r\nv   = [11  12]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1    2     3     4     5\r\n        6    7     8     9     10\r\n        11   12   -Inf  -Inf  -Inf]\r\n\u003c/pre\u003e","function_template":"function comb = addVecToMat(mat, v)\r\n  comb = [mat; v];\r\nend","test_suite":"%%\r\nfiletext = fileread('addVecToMat.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nmat = ones(2);\r\nv   = 1:3;\r\ncomb_correct = [1 1 inf; 1 1 inf; 1 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3, 4);\r\nv   = [2 3];\r\ncomb_correct = [ones(3,4); 2 3 -inf -inf];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(2);\r\nv   = [2 3];\r\ncomb_correct = [1 1; 1 1; 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3);\r\nv   = 1:6;\r\ncomb_correct = [repmat([ones(1,3) inf(1,3)], 3, 1); 1:6];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":186,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-11T00:10:48.000Z","updated_at":"2025-11-29T16:14:21.000Z","published_at":"2017-12-11T00:10:48.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a row vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1Xs\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return a matrix with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em+1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e rows that conatains\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e over\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The number of columns is the larger between\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u0026gt;n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the matrix is padded with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u0026gt;s\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the vector is padded with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e-Inf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[inputs:\\nmat = [1  2\\n       3  4]\\nv   = [5  6  7  8]\\n\\noutput:\\ncomb = [1   2   Inf  Inf\\n        3   4   Inf  Inf\\n        5   6   7    8  ]\\n\\ninputs:\\nmat = [1   2   3   4   5\\n       6   7   8   9   10]\\nv   = [11  12]\\n\\noutput:\\ncomb = [1    2     3     4     5\\n        6    7     8     9     10\\n        11   12   -Inf  -Inf  -Inf]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44499,"title":"Capitilize the first letter of every word in a string","description":"For a given input string, capitalize every letter at the beginning of a word, and transform the rest of the letters to lower-case.\r\n\r\nNon-letter characters should remain the same.\r\n\r\nYou can assume there is only one space between every two words.\r\n\r\nExamples:\r\n\r\n  input:  'this is BETTER than C++'\r\n  output: 'This Is Better Than C++'\r\n\r\n  input:  'hEy, tHis iS vErY wroNg!'\r\n  output: 'Hey, This Is Very Wrong!'","description_html":"\u003cp\u003eFor a given input string, capitalize every letter at the beginning of a word, and transform the rest of the letters to lower-case.\u003c/p\u003e\u003cp\u003eNon-letter characters should remain the same.\u003c/p\u003e\u003cp\u003eYou can assume there is only one space between every two words.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput:  'this is BETTER than C++'\r\noutput: 'This Is Better Than C++'\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003einput:  'hEy, tHis iS vErY wroNg!'\r\noutput: 'Hey, This Is Very Wrong!'\r\n\u003c/pre\u003e","function_template":"function corrected = autoCase(sentence)\r\n    corrected = sentence;\r\nend","test_suite":"%%\r\nsentence  = 'this is BETTER than C++';\r\ncorrected = 'This Is Better Than C++';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'hEy, tHis iS vErY wroNg!';\r\ncorrected = 'Hey, This Is Very Wrong!';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'tHIS sENTENCE wILL bE iNVERTED';\r\ncorrected = 'This Sentence Will Be Inverted';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'This Sentence Will Not Be Changed';\r\ncorrected = 'This Sentence Will Not Be Changed';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'HELLO THERE';\r\ncorrected = 'Hello There';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'AlTeRnAtInG cApS';\r\ncorrected = 'Alternating Caps';\r\nassert(isequal(autoCase(sentence), corrected))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":118,"test_suite_updated_at":"2018-07-13T15:19:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-15T01:08:57.000Z","updated_at":"2025-11-29T16:31:33.000Z","published_at":"2018-01-15T01:08: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\u003eFor a given input string, capitalize every letter at the beginning of a word, and transform the rest of the letters to lower-case.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNon-letter characters should remain the same.\u003c/w:t\u003e\u003c/w:r\u003e\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 can assume there is only one space between every two words.\u003c/w:t\u003e\u003c/w:r\u003e\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:  'this is BETTER than C++'\\noutput: 'This Is Better Than C++'\\n\\ninput:  'hEy, tHis iS vErY wroNg!'\\noutput: 'Hey, This Is Very Wrong!']]\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":44476,"title":"How many unique Pythagorean triples?","description":"For a given integer |n|, return all \u003chttps://en.wikipedia.org/wiki/Pythagorean_triple Pythagorean triples\u003e that inlude numbers smaller or equal to |n|.\r\n\r\nA Pythagorean triple consist of three positive integers |{a, b, c}| such that:\r\n\r\n a \u003c b \u003c c,\r\n a^2 + b^2 = c^2\r\n\r\nThe triples should be retured in a matrix with tree columns, where each row contains a different triple. Every row needs to be sorted in ascending order ( |a| in the first column, |b| in the second and |c| in the third), and the first column must also be sorted.\r\n\r\nExample:\r\n\r\n  Input:  n   = 16\r\n  Output: mat = [3,  4, 5\r\n                 5, 12, 13 \r\n                 6,  8, 10 \r\n                 9, 12, 15]\r\n\r\nIf |n| is not an integer, or it is smaller than 5, the function should return an empty matrix.","description_html":"\u003cp\u003eFor a given integer \u003ctt\u003en\u003c/tt\u003e, return all \u003ca href = \"https://en.wikipedia.org/wiki/Pythagorean_triple\"\u003ePythagorean triples\u003c/a\u003e that inlude numbers smaller or equal to \u003ctt\u003en\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eA Pythagorean triple consist of three positive integers \u003ctt\u003e{a, b, c}\u003c/tt\u003e such that:\u003c/p\u003e\u003cpre\u003e a \u0026lt; b \u0026lt; c,\r\n a^2 + b^2 = c^2\u003c/pre\u003e\u003cp\u003eThe triples should be retured in a matrix with tree columns, where each row contains a different triple. Every row needs to be sorted in ascending order ( \u003ctt\u003ea\u003c/tt\u003e in the first column, \u003ctt\u003eb\u003c/tt\u003e in the second and \u003ctt\u003ec\u003c/tt\u003e in the third), and the first column must also be sorted.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 16\r\nOutput: mat = [3,  4, 5\r\n               5, 12, 13 \r\n               6,  8, 10 \r\n               9, 12, 15]\r\n\u003c/pre\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not an integer, or it is smaller than 5, the function should return an empty matrix.\u003c/p\u003e","function_template":"function mat = triples(n)\r\n    mat = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('triples.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = [];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 20.5;\r\nmat_correct = [];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 15;\r\nmat_correct = [3,  4, 5; 5, 12, 13; 6,  8, 10; 9, 12, 15];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 16;\r\nmat_correct = [3,  4, 5; 5, 12, 13; 6,  8, 10; 9, 12, 15];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 100\r\nmat_correct = ...\r\n    [3     4     5;\r\n     5    12    13;\r\n     6     8    10;\r\n     7    24    25;\r\n     8    15    17;\r\n     9    12    15;\r\n     9    40    41;\r\n    10    24    26;\r\n    11    60    61;\r\n    12    16    20;\r\n    12    35    37;\r\n    13    84    85;\r\n    14    48    50;\r\n    15    20    25;\r\n    15    36    39;\r\n    16    30    34;\r\n    16    63    65;\r\n    18    24    30;\r\n    18    80    82;\r\n    20    21    29;\r\n    20    48    52;\r\n    21    28    35;\r\n    21    72    75;\r\n    24    32    40;\r\n    24    45    51;\r\n    24    70    74;\r\n    25    60    65;\r\n    27    36    45;\r\n    28    45    53;\r\n    28    96   100;\r\n    30    40    50;\r\n    30    72    78;\r\n    32    60    68;\r\n    33    44    55;\r\n    33    56    65;\r\n    35    84    91;\r\n    36    48    60;\r\n    36    77    85;\r\n    39    52    65;\r\n    39    80    89;\r\n    40    42    58;\r\n    40    75    85;\r\n    42    56    70;\r\n    45    60    75;\r\n    48    55    73;\r\n    48    64    80;\r\n    51    68    85;\r\n    54    72    90;\r\n    57    76    95;\r\n    60    63    87;\r\n    60    80   100;\r\n    65    72    97];\r\n\r\n%%\r\nn = 1000;\r\ns_correct = [881, 3];\r\nassert(isequal(size(triples(n)), s_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":150,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-31T20:29:09.000Z","updated_at":"2026-02-24T14:05:30.000Z","published_at":"2017-12-31T20:29:09.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 integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return all\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://en.wikipedia.org/wiki/Pythagorean_triple\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePythagorean triples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e that inlude numbers smaller or equal 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: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.\u003c/w:t\u003e\u003c/w:r\u003e\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 Pythagorean triple consist of three positive integers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e{a, b, c}\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that:\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 \u003c b \u003c c,\\n a^2 + b^2 = c^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\u003eThe triples should be retured in a matrix with tree columns, where each row contains a different triple. Every row needs to be sorted in ascending order (\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\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the first column,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the second 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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the third), and the first column must also be sorted.\u003c/w:t\u003e\u003c/w:r\u003e\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:  n   = 16\\nOutput: mat = [3,  4, 5\\n               5, 12, 13 \\n               6,  8, 10 \\n               9, 12, 15]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not an integer, or it is smaller than 5, the function should return an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44454,"title":"How many Integers?","description":"Count the integers in a given vector |v|.\r\n\r\nYou *must* use a loop to count each element separately.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\n  Output: n = 6    (9.0 is also an integer)\r\n\r\n  Input:  v = [1.2, 2.3, 4.5]\r\n  Output: n = 0","description_html":"\u003cp\u003eCount the integers in a given vector \u003ctt\u003ev\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eYou \u003cb\u003emust\u003c/b\u003e use a loop to count each element separately.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nOutput: n = 6    (9.0 is also an integer)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.2, 2.3, 4.5]\r\nOutput: n = 0\r\n\u003c/pre\u003e","function_template":"function n = integerCount(v)\r\n    % write your code instead of this line\r\n    n = length(v);\r\n    % \r\nend","test_suite":"%%\r\nfiletext = fileread('integerCount.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nn_correct = 6;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = [1.6, 5.7, 4.8, -3.5, 5.3, 9.2, -1.1, 0.01, 1.2]\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = []\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":464,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:23:07.000Z","updated_at":"2026-02-11T15:35:06.000Z","published_at":"2017-12-16T22:23:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCount the integers in a given 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.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emust\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use a loop to count each element separately.\u003c/w:t\u003e\u003c/w:r\u003e\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:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\\nOutput: n = 6    (9.0 is also an integer)\\n\\nInput:  v = [1.2, 2.3, 4.5]\\nOutput: n = 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44468,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":163,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T22:09:37.000Z","updated_at":"2026-03-11T17:00:04.000Z","published_at":"2017-12-24T22:09:37.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44469,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":482,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2017-12-24T22:09:41.000Z","updated_at":"2026-02-14T08:55:51.000Z","published_at":"2017-12-24T22:09:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"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":44483,"title":"Separate even from odd numbers in a vector - without loops","description":"*Without using loops*, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\n  Output: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\r\n  Input:  v = [2\r\n               7\r\n               0\r\n               3\r\n               2]\r\n\r\n  Output: w = [7\r\n               3\r\n               2\r\n               0\r\n               2]\r\n\r\n  Input:  v = []\r\n  Output: w = []\r\n","description_html":"\u003cp\u003e\u003cb\u003eWithout using loops\u003c/b\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [2\r\n             7\r\n             0\r\n             3\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput: w = [7\r\n             3\r\n             2\r\n             0\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = []\r\nOutput: w = []\r\n\u003c/pre\u003e","function_template":"function w = oddEven(v)\r\n    w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('oddEven.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('oddEven.m');\r\nloopUsed = any(strfind(filetext, 'while')) || any(strfind(filetext, 'for'));\r\nassert(~loopUsed, 'Loops are forbidden')\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [2; 7; 0; 3; 2];\r\nw_correct = [7; 3; 2; 0; 2];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [1, 0, 2, 9, 3, 8, 8, 4];\r\nw_correct = [1, 9, 3, 0, 2, 8, 8, 4];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nodd  = 2 * randi([-4, 4], 1, randi([4,10])) - 1;\r\neven = 2 * randi([-4, 4], 1, randi([4,10]));\r\nv = [even, odd];\r\nw_correct = [odd, even];\r\nassert(isequal(oddEven(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":392,"test_suite_updated_at":"2018-01-07T23:06:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T11:53:55.000Z","updated_at":"2026-02-11T19:26:16.000Z","published_at":"2018-01-07T11:53:55.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\u003eWithout using loops\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\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:  v = [1, 0, 2, 9, 3, 8, 8, 4]\\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\\n\\nInput:  v = [2\\n             7\\n             0\\n             3\\n             2]\\n\\nOutput: w = [7\\n             3\\n             2\\n             0\\n             2]\\n\\nInput:  v = []\\nOutput: w = []]]\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":44416,"title":"Sum of adjacent elements in a vector","description":"Given a vector v, return a vector s containting the sum of every two adjacent elements in the vector.\r\n\r\nEvery element s(i) contains the sum of v(i) and v(i+1).\r\n\r\nExample:\r\n\r\n v = [1, 2, 4, 4, 5, 8]\r\n s = [3, 6, 8, 9, 13]","description_html":"\u003cp\u003eGiven a vector v, return a vector s containting the sum of every two adjacent elements in the vector.\u003c/p\u003e\u003cp\u003eEvery element s(i) contains the sum of v(i) and v(i+1).\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e v = [1, 2, 4, 4, 5, 8]\r\n s = [3, 6, 8, 9, 13]\u003c/pre\u003e","function_template":"function s = summ(v)\r\n  s = 2*v;\r\nend","test_suite":"%%\r\nfiletext = fileread('summ.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = randi(10, 1, randi(10));\r\ns = summ(v);\r\nassert(length(s) == length(v) - 1)\r\n\r\n%%\r\nv = 1:10;\r\ns_correct = 3:2:19;\r\nassert(isequal(summ(v),s_correct))\r\n\r\n%%\r\nv = [1; 2; 4; 4; 5; 8];\r\ns_correct = [3; 6; 8; 9; 13];\r\nassert(isequal(summ(v),s_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":583,"test_suite_updated_at":"2017-12-03T20:37:51.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-26T22:53:31.000Z","updated_at":"2026-02-05T19:43:52.000Z","published_at":"2017-11-26T22:53: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 a vector v, return a vector s containting the sum of every two adjacent elements in the vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery element s(i) contains the sum of v(i) and v(i+1).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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[ v = [1, 2, 4, 4, 5, 8]\\n s = [3, 6, 8, 9, 13]]]\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":44484,"title":"Separate even from odd numbers in a vector - with a loop","description":"*Using a loop*, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\n  Output: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\r\n  Input:  v = [2\r\n               7\r\n               0\r\n               3\r\n               2]\r\n\r\n  Output: w = [7\r\n               3\r\n               2\r\n               0\r\n               2]\r\n\r\n  Input:  v = []\r\n  Output: w = []\r\n","description_html":"\u003cp\u003e\u003cb\u003eUsing a loop\u003c/b\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [2\r\n             7\r\n             0\r\n             3\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput: w = [7\r\n             3\r\n             2\r\n             0\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = []\r\nOutput: w = []\r\n\u003c/pre\u003e","function_template":"function w = oddEven(v)\r\n    w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('oddEven.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('oddEven.m');\r\nloopUsed = ~isempty(strfind(filetext, 'while')) || ~isempty(strfind(filetext, 'for'));\r\nassert(loopUsed, 'Must use at least one loop')\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [2; 7; 0; 3; 2];\r\nw_correct = [7; 3; 2; 0; 2];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [1, 0, 2, 9, 3, 8, 8, 4];\r\nw_correct = [1, 9, 3, 0, 2, 8, 8, 4];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nodd  = 2 * randi([-4, 4], 1, randi([4,10])) - 1;\r\neven = 2 * randi([-4, 4], 1, randi([4,10]));\r\nv = [even, odd];\r\nw_correct = [odd, even];\r\nassert(isequal(oddEven(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":454,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T12:16:14.000Z","updated_at":"2026-02-11T19:24:54.000Z","published_at":"2018-01-07T12:16:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eUsing a loop\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\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:  v = [1, 0, 2, 9, 3, 8, 8, 4]\\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\\n\\nInput:  v = [2\\n             7\\n             0\\n             3\\n             2]\\n\\nOutput: w = [7\\n             3\\n             2\\n             0\\n             2]\\n\\nInput:  v = []\\nOutput: w = []]]\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":44492,"title":"Approximate the cosine function ","description":"Without using MATLAB trigonometric functions, calculate the cosine of an argument x to a precision of 0.0001\r\nHint: You may wish to consider the cosine Maclaurin series.","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: 51.5px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 25.75px; transform-origin: 407px 25.75px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21.5px; 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.75px; text-align: left; transform-origin: 384px 10.75px; 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: 262px 8px; transform-origin: 262px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWithout using MATLAB trigonometric functions, calculate the cosine of an argument\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003ex\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52.5px 8px; transform-origin: 52.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e to a precision of\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 24px 8px; transform-origin: 24px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003e0.0001\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: 16px 8px; transform-origin: 16px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eHint:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 93.5px 8px; transform-origin: 93.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e You may wish to consider the\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://en.wikipedia.org/wiki/Taylor_series#Trigonometric_functions\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ecosine Maclaurin series\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = myCos(x)\r\n    y = 1 - 0.5*x^2;\r\nend","test_suite":"%%\r\nfiletext = fileread('myCos.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n\r\n%%\r\nfiletext = fileread('myCos.m');\r\ntrigUsed = any(strfind(filetext, 'cos')) || any(strfind(filetext, 'sin')) ||...\r\n     any(strfind(filetext, 'sec')) || any(strfind(filetext, 'tan')) || any(strfind(filetext, 'cot'));\r\nassert(~trigUsed, 'Cannot use MATLAB trigonometric functions')\r\n\r\n%%\r\nx = 0;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n\r\n%%\r\nx = pi;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n\r\n%%\r\nx = pi/2;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n\r\n%%\r\nx = 5*pi/3;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":140356,"edited_by":223089,"edited_at":"2022-10-17T13:07:34.000Z","deleted_by":null,"deleted_at":null,"solvers_count":343,"test_suite_updated_at":"2022-10-17T13:07:34.000Z","rescore_all_solutions":false,"group_id":61,"created_at":"2018-01-07T23:20:12.000Z","updated_at":"2026-02-11T20:08:56.000Z","published_at":"2018-01-07T23:20:12.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\u003eWithout using MATLAB trigonometric functions, calculate the cosine of an argument\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 a precision 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\u003e0.0001\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e You may wish to consider 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=\\\"https://en.wikipedia.org/wiki/Taylor_series#Trigonometric_functions\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecosine Maclaurin series\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44455,"title":"Find the average of a random sequance","description":"Write a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\r\n\r\nAt each iteration a random integer between 0 and 10 is generated.\r\n\r\nOnly if the number is positive, it is added to the sequence.\r\n\r\nThe loop terminates when the number 0 is generated. This number is not considered for the mean.\r\n\r\n*You are not allowed to use the functions |sum()| and |mean()|*\r\n\r\nExamples:\r\n\r\n  Random sequence is: 4, 3, 5, 10, 3, 0\r\n  Output is: 5\r\n\r\n  Random sequence is: 0\r\n  Output is 0\r\n\r\n  Random sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\n  Output is: 4\r\n\r\n*Note*: the function does not have an input. The output depends on the state of the random numbers generator.","description_html":"\u003cp\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/p\u003e\u003cp\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/p\u003e\u003cp\u003eOnly if the number is positive, it is added to the sequence.\u003c/p\u003e\u003cp\u003eThe loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/p\u003e\u003cp\u003e\u003cb\u003eYou are not allowed to use the functions \u003ctt\u003esum()\u003c/tt\u003e and \u003ctt\u003emean()\u003c/tt\u003e\u003c/b\u003e\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 4, 3, 5, 10, 3, 0\r\nOutput is: 5\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 0\r\nOutput is 0\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\nOutput is: 4\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eNote\u003c/b\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\u003c/p\u003e","function_template":"function average = MeanWhile()\r\n    average = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'sum')),'sum() function is forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'mean')),'mean() function is forbidden')\r\n\r\n%%\r\nrng(1);\r\nav_correct = 5.5;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(2);\r\nav_correct = 4;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(3);\r\nav_correct = 5.25;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(7);\r\nav_correct = 0;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(0);\r\nav_correct = 6.571428571428571;\r\nassert(isequal(MeanWhile(),av_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":416,"test_suite_updated_at":"2017-12-17T07:32:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:37:19.000Z","updated_at":"2026-03-10T18:45:32.000Z","published_at":"2017-12-17T07:32:04.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eOnly if the number is positive, it is added to the sequence.\u003c/w:t\u003e\u003c/w:r\u003e\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 loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/w:t\u003e\u003c/w:r\u003e\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 are not allowed to use 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:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esum()\u003c/w:t\u003e\u003c/w:r\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:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emean()\u003c/w:t\u003e\u003c/w:r\u003e\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[Random sequence is: 4, 3, 5, 10, 3, 0\\nOutput is: 5\\n\\nRandom sequence is: 0\\nOutput is 0\\n\\nRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\\nOutput is: 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\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":44457,"title":"Triangle of numbers","description":"Create a matrix with the integers from 1 to |n| arranged in a triangular shape.\r\n\r\nEvery row |i| of the matrix contains |i| integers, and the rest of the elements are zeros.\r\n\r\nExamples:\r\n\r\n  Input:  n = 6\r\n  Output: mat = [1 0 0\r\n                 2 3 0\r\n                 4 5 6]\r\n\r\n  Input:  n = 12\r\n  Output: mat = [1  0  0  0 \r\n                 2  3  0  0 \r\n                 4  5  6  0 \r\n                 7  8  9  10\r\n                 11 12 0  0]","description_html":"\u003cp\u003eCreate a matrix with the integers from 1 to \u003ctt\u003en\u003c/tt\u003e arranged in a triangular shape.\u003c/p\u003e\u003cp\u003eEvery row \u003ctt\u003ei\u003c/tt\u003e of the matrix contains \u003ctt\u003ei\u003c/tt\u003e integers, and the rest of the elements are zeros.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 6\r\nOutput: mat = [1 0 0\r\n               2 3 0\r\n               4 5 6]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 12\r\nOutput: mat = [1  0  0  0 \r\n               2  3  0  0 \r\n               4  5  6  0 \r\n               7  8  9  10\r\n               11 12 0  0]\r\n\u003c/pre\u003e","function_template":"function mat = triangle(n)\r\n    mat = 1:n;\r\nend","test_suite":"%%\r\nfiletext = fileread('triangle.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nmat_correct = [];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 1;\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 6;\r\nmat_correct = [1 0 0; 2 3 0; 4 5 6];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 12;\r\nmat_correct = [1 0 0 0; 2 3 0 0; 4 5 6 0; 7 8 9 10; 11 12 0 0];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 50;\r\nmat_correct = [1,zeros(1,8); 2:3,zeros(1,7); 4:6,zeros(1,6);\r\n    7:10,zeros(1,5); 11:15,zeros(1,4); 16:21,zeros(1,3);\r\n    22:28,0,0; ; 29:36,0; 37:45; 46:50,zeros(1,4)];\r\nassert(isequal(triangle(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-17T08:43:23.000Z","updated_at":"2026-02-11T20:05:28.000Z","published_at":"2017-12-17T08:43:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate a matrix with the integers from 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: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 arranged in a triangular shape.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eEvery row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the matrix contains\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e integers, and the rest of the elements are zeros.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n = 6\\nOutput: mat = [1 0 0\\n               2 3 0\\n               4 5 6]\\n\\nInput:  n = 12\\nOutput: mat = [1  0  0  0 \\n               2  3  0  0 \\n               4  5  6  0 \\n               7  8  9  10\\n               11 12 0  0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44401,"title":"Vertical matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 8  9  3  9\r\n      9  6  5  2\r\n      2  1  9  9\r\n  \r\n  y = 2  1  3  2\r\n      8  6  5  9\r\n      9  9  9  9\r\n      9  9  9  9\r\n      8  6  5  9\r\n      2  1  3  2","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 8  9  3  9\r\n    9  6  5  2\r\n    2  1  9  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 2  1  3  2\r\n    8  6  5  9\r\n    9  9  9  9\r\n    9  9  9  9\r\n    8  6  5  9\r\n    2  1  3  2\r\n\u003c/pre\u003e","function_template":"function y = upAndDown(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0;0];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = zeros(10);\r\nx(7,4) = 1;\r\ny_correct = zeros(20,10);\r\ny_correct(10:11,4) = [1;1];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 4 3 2; 1 4 3 2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = [8  9  3  9; 9  6  5  2; 2  1  9  9];\r\ny_correct = [2  1  3  2; 8  6  5  9; 9  9  9  9;\r\n             9  9  9  9; 8  6  5  9; 2  1  3  2];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x; x];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x; flipud(x)];\r\nassert(isequal(upAndDown(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nc = [1:3,3:-1:1]';\r\ny_correct = [c,c+3,c+6];\r\nassert(isequal(upAndDown(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":340,"test_suite_updated_at":"2018-05-13T07:02:36.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2017-11-12T07:18:04.000Z","updated_at":"2026-02-11T19:50:48.000Z","published_at":"2017-11-12T07:31:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x with n rows and m columns, return a matrix y with 2n rows and m columns, such that every column in x is sorted from low to high and then from high to low.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x = 8  9  3  9\\n    9  6  5  2\\n    2  1  9  9\\n\\ny = 2  1  3  2\\n    8  6  5  9\\n    9  9  9  9\\n    9  9  9  9\\n    8  6  5  9\\n    2  1  3  2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44447,"title":"Eye Squared","description":"For a positive integer |n| create the identity matrix with |n| elements.\r\n\r\nIn case it is not possible to produce an identity matrix with exactly |n| elements, return an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n = 9\r\n  Output: I = [1 0 0\r\n               0 1 0\r\n               0 0 1]\r\n\r\n  Input:  n = 8\r\n  Output: I = []","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e create the identity matrix with \u003ctt\u003en\u003c/tt\u003e elements.\u003c/p\u003e\u003cp\u003eIn case it is not possible to produce an identity matrix with exactly \u003ctt\u003en\u003c/tt\u003e elements, return an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 9\r\nOutput: I = [1 0 0\r\n             0 1 0\r\n             0 0 1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 8\r\nOutput: I = []\r\n\u003c/pre\u003e","function_template":"function I = eyeSquared(n)\r\n    I = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('eyeSquared.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 1;\r\nI_correct = 1;\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4;\r\nI_correct = [1 0; 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 9;\r\nI_correct = [1 0 0; 0 1 0; 0 0 1];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = -9;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 10;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n\r\n%%\r\nn = 4.1;\r\nI_correct = [];\r\nassert(isequal(eyeSquared(n),I_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":234,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-11T00:36:01.000Z","updated_at":"2026-03-11T16:59:00.000Z","published_at":"2017-12-11T00:36:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e create the identity matrix with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn case it is not possible to produce an identity matrix with exactly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e elements, return an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n = 9\\nOutput: I = [1 0 0\\n             0 1 0\\n             0 0 1]\\n\\nInput:  n = 8\\nOutput: I = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44392,"title":"Sum of Two Numbers","description":"Given two integer numbers x and y, calculate their sum and put it in z.\r\n\r\nExamples:\r\n\r\n  Inputs x = 2, y = 4\r\n  Output z is 6\r\n\r\n  Inputs x = 1, y = -4\r\n  Output z is -3","description_html":"\u003cp\u003eGiven two integer numbers x and y, calculate their sum and put it in z.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInputs x = 2, y = 4\r\nOutput z is 6\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInputs x = 1, y = -4\r\nOutput z is -3\r\n\u003c/pre\u003e","function_template":"function z = sumTwo(x, y)\r\n  z = x * y;\r\nend","test_suite":"%%\r\nx = 1; y = 2;\r\nz_correct = 3;\r\nassert(isequal(sumTwo(x,y),z_correct));\r\n\r\n%%\r\nx = -21; y = 32;\r\nz_correct = 11;\r\nassert(isequal(sumTwo(x,y),z_correct));\r\n\r\n%%\r\nx = randi(100); y = randi(100);\r\nz_correct = sqrt(x^2 + y^2 + 2*x*y);\r\nassert(isequal(sumTwo(x,y),z_correct));\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":3,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":782,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-10-29T12:44:25.000Z","updated_at":"2026-02-24T00:51:23.000Z","published_at":"2017-10-29T12:44:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two integer numbers x and y, calculate their sum and put it in z.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Inputs x = 2, y = 4\\nOutput z is 6\\n\\nInputs x = 1, y = -4\\nOutput z is -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":44445,"title":"Tax Calculator","description":"Calculate the tax for a given income.\r\n\r\n10% tax is paid for any income up to $2,000.\r\n\r\n20% tax is paid for additional income up to $3,000.\r\n\r\n30% tax is paid for any additional income over $3,000.\r\n\r\nFor example, the tax for an income of $2,500 is calculated as follows:\r\n\r\n  $2,000 * 10% + $500 * 20% = $300","description_html":"\u003cp\u003eCalculate the tax for a given income.\u003c/p\u003e\u003cp\u003e10% tax is paid for any income up to $2,000.\u003c/p\u003e\u003cp\u003e20% tax is paid for additional income up to $3,000.\u003c/p\u003e\u003cp\u003e30% tax is paid for any additional income over $3,000.\u003c/p\u003e\u003cp\u003eFor example, the tax for an income of $2,500 is calculated as follows:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e$2,000 * 10% + $500 * 20% = $300\r\n\u003c/pre\u003e","function_template":"function tax = taxFor(income)\r\n  tax = income / 10;\r\nend","test_suite":"%%\r\nincome = 0;\r\ntax_correct = 0;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 100;\r\ntax_correct = 10;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 1000;\r\ntax_correct = 100;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 2000;\r\ntax_correct = 200;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 2500;\r\ntax_correct = 300;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 3000;\r\ntax_correct = 400;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nincome = 5000;\r\ntax_correct = 1000;\r\nassert(isequal(taxFor(income),tax_correct))\r\n\r\n%%\r\nfiletext = fileread('taxFor.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":215,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-10T23:09:53.000Z","updated_at":"2026-03-11T08:23:52.000Z","published_at":"2017-12-10T23:09:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCalculate the tax for a given income.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003e10% tax is paid for any income up to $2,000.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003e20% tax is paid for additional income up to $3,000.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003e30% tax is paid for any additional income over $3,000.\u003c/w:t\u003e\u003c/w:r\u003e\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 tax for an income of $2,500 is calculated as follows:\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,000 * 10% + $500 * 20% = $300]]\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":44437,"title":"How many days in a month?","description":"Return the number of days in a given month in 2017. If the input is not a valid month number, return -1.\r\n\r\nExamples:\r\n\r\n  Input: m = 1\r\n  Outpu: d = 31\r\n\r\n  Input:  m = 2\r\n  Output: d = 28\r\n\r\n  Input:  m = 13\r\n  Output: d = -1\r\n\r\nYou *cannot* use IF statements","description_html":"\u003cp\u003eReturn the number of days in a given month in 2017. If the input is not a valid month number, return -1.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput: m = 1\r\nOutpu: d = 31\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  m = 2\r\nOutput: d = 28\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  m = 13\r\nOutput: d = -1\r\n\u003c/pre\u003e\u003cp\u003eYou \u003cb\u003ecannot\u003c/b\u003e use IF statements\u003c/p\u003e","function_template":"function d = daysInMonth(m)\r\n  d = 31;\r\nend","test_suite":"%%\r\nfiletext = fileread('daysInMonth.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\nassert(isempty(strfind(filetext, 'if')),'IF statements are forbidden')\r\n\r\n%%\r\nm = 1;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 2;\r\nd_correct = 28;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 3;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 4;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 5;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 6;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 7;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 8;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 9;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 10;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 11;\r\nd_correct = 30;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 12;\r\nd_correct = 31;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = 13;\r\nd_correct = -1;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\r\n%%\r\nm = randi([-100 0]);\r\nd_correct = -1;\r\nassert(isequal(daysInMonth(m),d_correct))\r\n\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":495,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T20:28:10.000Z","updated_at":"2026-04-02T12:47:30.000Z","published_at":"2017-12-03T20:28: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\u003eReturn the number of days in a given month in 2017. If the input is not a valid month number, return -1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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: m = 1\\nOutpu: d = 31\\n\\nInput:  m = 2\\nOutput: d = 28\\n\\nInput:  m = 13\\nOutput: d = -1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecannot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use IF statements\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44402,"title":"Horizontal matrix sort","description":"Given a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\r\n\r\nExample:\r\n\r\n  x = 9  2  8  1\r\n      5  4  9  8\r\n      8  9  6  9\r\n  \r\n  y = 1  2  8  9  9  8  2  1\r\n      4  5  8  9  9  8  5  4\r\n      6  8  9  9  9  9  8  6","description_html":"\u003cp\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 9  2  8  1\r\n    5  4  9  8\r\n    8  9  6  9\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey = 1  2  8  9  9  8  2  1\r\n    4  5  8  9  9  8  5  4\r\n    6  8  9  9  9  9  8  6\r\n\u003c/pre\u003e","function_template":"function y = backAndforth(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [];\r\ny_correct = [];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 0;\r\ny_correct = [0 0];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = zeros(100);\r\nx(41,68) = 1;\r\ny_correct = zeros(100,200);\r\ny_correct(41,100:101) = [1,1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1 4 3 2];\r\ny_correct = [1 2 3 4 4 3 2 1];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [x,fliplr(x)];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = (1:10)';\r\ny_correct = [x,x];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [1; 4; 3; 2];\r\ny_correct = [1 1; 4 4; 3 3; 2 2];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = [9  2  8  1; 5  4  9  8; 8  9  6  9];\r\ny_correct = [1  2  8  9  9  8  2  1;\r\n             4  5  8  9  9  8  5  4;\r\n             6  8  9  9  9  9  8  6];\r\nassert(isequal(backAndforth(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:9,[3,3]);\r\nr = [1:3:7,7:-3:1];\r\ny_correct = [r;r+1;r+2];\r\nassert(isequal(backAndforth(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":"2018-01-02T21:54:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-12T07:54:27.000Z","updated_at":"2026-03-29T20:13:01.000Z","published_at":"2017-11-12T07:59:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x with n rows and m columns, return a matrix y with n rows and 2m columns, such that every row in x is sorted from low to high and then from high to low.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x = 9  2  8  1\\n    5  4  9  8\\n    8  9  6  9\\n\\ny = 1  2  8  9  9  8  2  1\\n    4  5  8  9  9  8  5  4\\n    6  8  9  9  9  9  8  6]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44439,"title":"Remove the air bubbles from a vector","description":"_*A reduced version of Problem 112*_\r\n\r\nGiven a column vector v, return a vector w in which all the zeros have \"bubbled\" to the top. The order of the remaining nonzero numbers in the vector should be preserved.\r\n\r\nExample:\r\n\r\n  Input  v = [1\r\n              3\r\n              0\r\n              5\r\n              0\r\n              -1]\r\n\r\n  Output w = [0\r\n              0\r\n              1\r\n              3\r\n              5\r\n              -1]","description_html":"\u003cp\u003e\u003ci\u003e\u003cb\u003eA reduced version of Problem 112\u003c/b\u003e\u003c/i\u003e\u003c/p\u003e\u003cp\u003eGiven a column vector v, return a vector w in which all the zeros have \"bubbled\" to the top. The order of the remaining nonzero numbers in the vector should be preserved.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput  v = [1\r\n            3\r\n            0\r\n            5\r\n            0\r\n            -1]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput w = [0\r\n            0\r\n            1\r\n            3\r\n            5\r\n            -1]\r\n\u003c/pre\u003e","function_template":"function w = bubbles(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('bubbles.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1 3 0 5 0 -1]';\r\nw_correct = [0 0 1 3 5 -1]';\r\nassert(isequal(bubbles(v),w_correct))\r\n\r\n%%\r\nv = [0 0 9 2 6]';\r\nw_correct = v;\r\nassert(isequal(bubbles(v),w_correct))\r\n\r\n%%\r\nv = [1 3 5 -1]';\r\nw_correct = v;\r\nassert(isequal(bubbles(v),w_correct))\r\n\r\n%%\r\nv = [0 1 0 1 1 1 0]';\r\nw_correct = [0 0 0 1 1 1 1]';\r\nassert(isequal(bubbles(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":193,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T21:41:30.000Z","updated_at":"2026-03-30T19:08:33.000Z","published_at":"2017-12-03T21:41: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\",\"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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA reduced version of Problem 112\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a column vector v, return a vector w in which all the zeros have \\\"bubbled\\\" to the top. The order of the remaining nonzero numbers in the vector should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\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  v = [1\\n            3\\n            0\\n            5\\n            0\\n            -1]\\n\\nOutput w = [0\\n            0\\n            1\\n            3\\n            5\\n            -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":44436,"title":"Find the largest number","description":"Find the largest number |x| among 4 numbers given as variables |a|, |b|, |c|, and |d|.\r\n\r\nExample:\r\n\r\n  Input:  a = 4; b = 7; c = 1; d = 6;\r\n  Output: x = 7;\r\n\r\nYou must *NOT* use MATLAB built in functions such as min(), max() or sort()","description_html":"\u003cp\u003eFind the largest number \u003ctt\u003ex\u003c/tt\u003e among 4 numbers given as variables \u003ctt\u003ea\u003c/tt\u003e, \u003ctt\u003eb\u003c/tt\u003e, \u003ctt\u003ec\u003c/tt\u003e, and \u003ctt\u003ed\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  a = 4; b = 7; c = 1; d = 6;\r\nOutput: x = 7;\r\n\u003c/pre\u003e\u003cp\u003eYou must \u003cb\u003eNOT\u003c/b\u003e use MATLAB built in functions such as min(), max() or sort()\u003c/p\u003e","function_template":"function x = largest(a, b, c, d)\r\n  x = a;\r\nend","test_suite":"%%\r\nfiletext = fileread('largest.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\nassert(isempty(strfind(filetext, 'max')),'max() forbidden')\r\nassert(isempty(strfind(filetext, 'min')),'min() forbidden')\r\nassert(isempty(strfind(filetext, 'sort')),'sort() forbidden')\r\nassert(isempty(strfind(filetext, 'unique')),'unique() forbidden')\r\n\r\n%%\r\na = 4; b = 7; c = 1; d = 6;\r\nx_correct = 7;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 1; d = 1;\r\nx_correct = 1;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 4; b = 3; c = 2; d = 1;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 2; c = 3; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 3; d = 5;\r\nx_correct = 5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 2; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 2; b = 3; c = 1; d = 6.5;\r\nx_correct = 6.5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 5; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 9; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 1; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":504,"test_suite_updated_at":"2020-05-13T19:39:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T12:39:01.000Z","updated_at":"2026-02-08T06:30:02.000Z","published_at":"2017-12-03T12:39:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the largest number\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw: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 among 4 numbers given as variables\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\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ed\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\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:  a = 4; b = 7; c = 1; d = 6;\\nOutput: x = 7;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou must\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNOT\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use MATLAB built in functions such as min(), max() or sort()\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":44415,"title":"Remove the first, third and fifth rows of a matrix","description":"Given a matrix x with at least five rows, return a matrix y that includes all rows of x except for th 1st, the 3rd and 5th.\r\n\r\nExample:\r\n \r\n Input:\r\n x = [1 1 1;\r\n      2 2 2;\r\n      3 3 3;\r\n      4 4 4;\r\n      5 5 5;\r\n      6 6 6]\r\n\r\n Output:\r\n y = [2 2 2;\r\n      4 4 4;\r\n      6 6 6]","description_html":"\u003cp\u003eGiven a matrix x with at least five rows, return a matrix y that includes all rows of x except for th 1st, the 3rd and 5th.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input:\r\n x = [1 1 1;\r\n      2 2 2;\r\n      3 3 3;\r\n      4 4 4;\r\n      5 5 5;\r\n      6 6 6]\u003c/pre\u003e\u003cpre\u003e Output:\r\n y = [2 2 2;\r\n      4 4 4;\r\n      6 6 6]\u003c/pre\u003e","function_template":"function y = deleteThreeRows(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 1 1;\r\n     2 2 2;\r\n     3 3 3;\r\n     4 4 4;\r\n     5 5 5;\r\n     6 6 6];\r\ny_correct = [2 2 2;\r\n             4 4 4;\r\n             6 6 6];\r\nassert(isequal(deleteThreeRows(x),y_correct))\r\n\r\n%%\r\nx = (1:5)';\r\ny_correct = [2;4];\r\nassert(isequal(deleteThreeRows(x),y_correct))\r\n\r\n%%\r\nx = ones(8);\r\ny_correct = ones(5, 8);\r\nassert(isequal(deleteThreeRows(x),y_correct))","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":596,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-26T22:27:53.000Z","updated_at":"2026-02-05T19:42:12.000Z","published_at":"2017-11-26T22:27:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x with at least five rows, return a matrix y that includes all rows of x except for th 1st, the 3rd and 5th.\u003c/w:t\u003e\u003c/w:r\u003e\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:\\n x = [1 1 1;\\n      2 2 2;\\n      3 3 3;\\n      4 4 4;\\n      5 5 5;\\n      6 6 6]\\n\\n Output:\\n y = [2 2 2;\\n      4 4 4;\\n      6 6 6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44446,"title":"Add a vector to a matrix","description":"Given a matrix |mat| of size |mXn| and a row vector |v| of size |1Xs|, return a matrix with |m+1| rows that conatains |mat| over |v|.\r\nThe number of columns is the larger between |n| and |s|.\r\n\r\nIf |s\u003en|, the matrix is padded with |Inf|.\r\n\r\nIf |n\u003es|, the vector is padded with |-Inf|.\r\n\r\nExamples:\r\n\r\n  inputs:\r\n  mat = [1  2\r\n         3  4]\r\n  v   = [5  6  7  8]\r\n\r\n  output:\r\n  comb = [1   2   Inf  Inf\r\n          3   4   Inf  Inf\r\n          5   6   7    8  ]\r\n\r\n  inputs:\r\n  mat = [1   2   3   4   5\r\n         6   7   8   9   10]\r\n  v   = [11  12]\r\n\r\n  output:\r\n  comb = [1    2     3     4     5\r\n          6    7     8     9     10\r\n          11   12   -Inf  -Inf  -Inf]","description_html":"\u003cp\u003eGiven a matrix \u003ctt\u003emat\u003c/tt\u003e of size \u003ctt\u003emXn\u003c/tt\u003e and a row vector \u003ctt\u003ev\u003c/tt\u003e of size \u003ctt\u003e1Xs\u003c/tt\u003e, return a matrix with \u003ctt\u003em+1\u003c/tt\u003e rows that conatains \u003ctt\u003emat\u003c/tt\u003e over \u003ctt\u003ev\u003c/tt\u003e.\r\nThe number of columns is the larger between \u003ctt\u003en\u003c/tt\u003e and \u003ctt\u003es\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003es\u0026gt;n\u003c/tt\u003e, the matrix is padded with \u003ctt\u003eInf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eIf \u003ctt\u003en\u0026gt;s\u003c/tt\u003e, the vector is padded with \u003ctt\u003e-Inf\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1  2\r\n       3  4]\r\nv   = [5  6  7  8]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1   2   Inf  Inf\r\n        3   4   Inf  Inf\r\n        5   6   7    8  ]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003einputs:\r\nmat = [1   2   3   4   5\r\n       6   7   8   9   10]\r\nv   = [11  12]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput:\r\ncomb = [1    2     3     4     5\r\n        6    7     8     9     10\r\n        11   12   -Inf  -Inf  -Inf]\r\n\u003c/pre\u003e","function_template":"function comb = addVecToMat(mat, v)\r\n  comb = [mat; v];\r\nend","test_suite":"%%\r\nfiletext = fileread('addVecToMat.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nmat = ones(2);\r\nv   = 1:3;\r\ncomb_correct = [1 1 inf; 1 1 inf; 1 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3, 4);\r\nv   = [2 3];\r\ncomb_correct = [ones(3,4); 2 3 -inf -inf];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(2);\r\nv   = [2 3];\r\ncomb_correct = [1 1; 1 1; 2 3];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n%%\r\nmat = ones(3);\r\nv   = 1:6;\r\ncomb_correct = [repmat([ones(1,3) inf(1,3)], 3, 1); 1:6];\r\nassert(isequal(addVecToMat(mat, v), comb_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":186,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-11T00:10:48.000Z","updated_at":"2025-11-29T16:14:21.000Z","published_at":"2017-12-11T00:10:48.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a row vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1Xs\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return a matrix with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em+1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e rows that conatains\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e over\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The number of columns is the larger between\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u0026gt;n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the matrix is padded with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u0026gt;s\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the vector is padded with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e-Inf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[inputs:\\nmat = [1  2\\n       3  4]\\nv   = [5  6  7  8]\\n\\noutput:\\ncomb = [1   2   Inf  Inf\\n        3   4   Inf  Inf\\n        5   6   7    8  ]\\n\\ninputs:\\nmat = [1   2   3   4   5\\n       6   7   8   9   10]\\nv   = [11  12]\\n\\noutput:\\ncomb = [1    2     3     4     5\\n        6    7     8     9     10\\n        11   12   -Inf  -Inf  -Inf]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44499,"title":"Capitilize the first letter of every word in a string","description":"For a given input string, capitalize every letter at the beginning of a word, and transform the rest of the letters to lower-case.\r\n\r\nNon-letter characters should remain the same.\r\n\r\nYou can assume there is only one space between every two words.\r\n\r\nExamples:\r\n\r\n  input:  'this is BETTER than C++'\r\n  output: 'This Is Better Than C++'\r\n\r\n  input:  'hEy, tHis iS vErY wroNg!'\r\n  output: 'Hey, This Is Very Wrong!'","description_html":"\u003cp\u003eFor a given input string, capitalize every letter at the beginning of a word, and transform the rest of the letters to lower-case.\u003c/p\u003e\u003cp\u003eNon-letter characters should remain the same.\u003c/p\u003e\u003cp\u003eYou can assume there is only one space between every two words.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput:  'this is BETTER than C++'\r\noutput: 'This Is Better Than C++'\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003einput:  'hEy, tHis iS vErY wroNg!'\r\noutput: 'Hey, This Is Very Wrong!'\r\n\u003c/pre\u003e","function_template":"function corrected = autoCase(sentence)\r\n    corrected = sentence;\r\nend","test_suite":"%%\r\nsentence  = 'this is BETTER than C++';\r\ncorrected = 'This Is Better Than C++';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'hEy, tHis iS vErY wroNg!';\r\ncorrected = 'Hey, This Is Very Wrong!';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'tHIS sENTENCE wILL bE iNVERTED';\r\ncorrected = 'This Sentence Will Be Inverted';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'This Sentence Will Not Be Changed';\r\ncorrected = 'This Sentence Will Not Be Changed';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'HELLO THERE';\r\ncorrected = 'Hello There';\r\nassert(isequal(autoCase(sentence), corrected))\r\n\r\n%%\r\nsentence  = 'AlTeRnAtInG cApS';\r\ncorrected = 'Alternating Caps';\r\nassert(isequal(autoCase(sentence), corrected))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":118,"test_suite_updated_at":"2018-07-13T15:19:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-15T01:08:57.000Z","updated_at":"2025-11-29T16:31:33.000Z","published_at":"2018-01-15T01:08: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\u003eFor a given input string, capitalize every letter at the beginning of a word, and transform the rest of the letters to lower-case.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNon-letter characters should remain the same.\u003c/w:t\u003e\u003c/w:r\u003e\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 can assume there is only one space between every two words.\u003c/w:t\u003e\u003c/w:r\u003e\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:  'this is BETTER than C++'\\noutput: 'This Is Better Than C++'\\n\\ninput:  'hEy, tHis iS vErY wroNg!'\\noutput: 'Hey, This Is Very Wrong!']]\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":44476,"title":"How many unique Pythagorean triples?","description":"For a given integer |n|, return all \u003chttps://en.wikipedia.org/wiki/Pythagorean_triple Pythagorean triples\u003e that inlude numbers smaller or equal to |n|.\r\n\r\nA Pythagorean triple consist of three positive integers |{a, b, c}| such that:\r\n\r\n a \u003c b \u003c c,\r\n a^2 + b^2 = c^2\r\n\r\nThe triples should be retured in a matrix with tree columns, where each row contains a different triple. Every row needs to be sorted in ascending order ( |a| in the first column, |b| in the second and |c| in the third), and the first column must also be sorted.\r\n\r\nExample:\r\n\r\n  Input:  n   = 16\r\n  Output: mat = [3,  4, 5\r\n                 5, 12, 13 \r\n                 6,  8, 10 \r\n                 9, 12, 15]\r\n\r\nIf |n| is not an integer, or it is smaller than 5, the function should return an empty matrix.","description_html":"\u003cp\u003eFor a given integer \u003ctt\u003en\u003c/tt\u003e, return all \u003ca href = \"https://en.wikipedia.org/wiki/Pythagorean_triple\"\u003ePythagorean triples\u003c/a\u003e that inlude numbers smaller or equal to \u003ctt\u003en\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eA Pythagorean triple consist of three positive integers \u003ctt\u003e{a, b, c}\u003c/tt\u003e such that:\u003c/p\u003e\u003cpre\u003e a \u0026lt; b \u0026lt; c,\r\n a^2 + b^2 = c^2\u003c/pre\u003e\u003cp\u003eThe triples should be retured in a matrix with tree columns, where each row contains a different triple. Every row needs to be sorted in ascending order ( \u003ctt\u003ea\u003c/tt\u003e in the first column, \u003ctt\u003eb\u003c/tt\u003e in the second and \u003ctt\u003ec\u003c/tt\u003e in the third), and the first column must also be sorted.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 16\r\nOutput: mat = [3,  4, 5\r\n               5, 12, 13 \r\n               6,  8, 10 \r\n               9, 12, 15]\r\n\u003c/pre\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not an integer, or it is smaller than 5, the function should return an empty matrix.\u003c/p\u003e","function_template":"function mat = triples(n)\r\n    mat = [];\r\nend","test_suite":"%%\r\nfiletext = fileread('triples.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = [];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 20.5;\r\nmat_correct = [];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 15;\r\nmat_correct = [3,  4, 5; 5, 12, 13; 6,  8, 10; 9, 12, 15];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 16;\r\nmat_correct = [3,  4, 5; 5, 12, 13; 6,  8, 10; 9, 12, 15];\r\nassert(isequal(triples(n),mat_correct))\r\n\r\n%%\r\nn = 100\r\nmat_correct = ...\r\n    [3     4     5;\r\n     5    12    13;\r\n     6     8    10;\r\n     7    24    25;\r\n     8    15    17;\r\n     9    12    15;\r\n     9    40    41;\r\n    10    24    26;\r\n    11    60    61;\r\n    12    16    20;\r\n    12    35    37;\r\n    13    84    85;\r\n    14    48    50;\r\n    15    20    25;\r\n    15    36    39;\r\n    16    30    34;\r\n    16    63    65;\r\n    18    24    30;\r\n    18    80    82;\r\n    20    21    29;\r\n    20    48    52;\r\n    21    28    35;\r\n    21    72    75;\r\n    24    32    40;\r\n    24    45    51;\r\n    24    70    74;\r\n    25    60    65;\r\n    27    36    45;\r\n    28    45    53;\r\n    28    96   100;\r\n    30    40    50;\r\n    30    72    78;\r\n    32    60    68;\r\n    33    44    55;\r\n    33    56    65;\r\n    35    84    91;\r\n    36    48    60;\r\n    36    77    85;\r\n    39    52    65;\r\n    39    80    89;\r\n    40    42    58;\r\n    40    75    85;\r\n    42    56    70;\r\n    45    60    75;\r\n    48    55    73;\r\n    48    64    80;\r\n    51    68    85;\r\n    54    72    90;\r\n    57    76    95;\r\n    60    63    87;\r\n    60    80   100;\r\n    65    72    97];\r\n\r\n%%\r\nn = 1000;\r\ns_correct = [881, 3];\r\nassert(isequal(size(triples(n)), s_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":150,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-31T20:29:09.000Z","updated_at":"2026-02-24T14:05:30.000Z","published_at":"2017-12-31T20:29:09.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 integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return all\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://en.wikipedia.org/wiki/Pythagorean_triple\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePythagorean triples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e that inlude numbers smaller or equal 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: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.\u003c/w:t\u003e\u003c/w:r\u003e\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 Pythagorean triple consist of three positive integers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e{a, b, c}\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that:\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 \u003c b \u003c c,\\n a^2 + b^2 = c^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\u003eThe triples should be retured in a matrix with tree columns, where each row contains a different triple. Every row needs to be sorted in ascending order (\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\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the first column,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the second 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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the third), and the first column must also be sorted.\u003c/w:t\u003e\u003c/w:r\u003e\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:  n   = 16\\nOutput: mat = [3,  4, 5\\n               5, 12, 13 \\n               6,  8, 10 \\n               9, 12, 15]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not an integer, or it is smaller than 5, the function should return an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44454,"title":"How many Integers?","description":"Count the integers in a given vector |v|.\r\n\r\nYou *must* use a loop to count each element separately.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\n  Output: n = 6    (9.0 is also an integer)\r\n\r\n  Input:  v = [1.2, 2.3, 4.5]\r\n  Output: n = 0","description_html":"\u003cp\u003eCount the integers in a given vector \u003ctt\u003ev\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eYou \u003cb\u003emust\u003c/b\u003e use a loop to count each element separately.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nOutput: n = 6    (9.0 is also an integer)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.2, 2.3, 4.5]\r\nOutput: n = 0\r\n\u003c/pre\u003e","function_template":"function n = integerCount(v)\r\n    % write your code instead of this line\r\n    n = length(v);\r\n    % \r\nend","test_suite":"%%\r\nfiletext = fileread('integerCount.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nn_correct = 6;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = [1.6, 5.7, 4.8, -3.5, 5.3, 9.2, -1.1, 0.01, 1.2]\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = []\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":464,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:23:07.000Z","updated_at":"2026-02-11T15:35:06.000Z","published_at":"2017-12-16T22:23:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCount the integers in a given 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.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emust\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use a loop to count each element separately.\u003c/w:t\u003e\u003c/w:r\u003e\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:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\\nOutput: n = 6    (9.0 is also an integer)\\n\\nInput:  v = [1.2, 2.3, 4.5]\\nOutput: n = 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44468,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":163,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T22:09:37.000Z","updated_at":"2026-03-11T17:00:04.000Z","published_at":"2017-12-24T22:09:37.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44469,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":482,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2017-12-24T22:09:41.000Z","updated_at":"2026-02-14T08:55:51.000Z","published_at":"2017-12-24T22:09:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"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":44483,"title":"Separate even from odd numbers in a vector - without loops","description":"*Without using loops*, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\n  Output: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\r\n  Input:  v = [2\r\n               7\r\n               0\r\n               3\r\n               2]\r\n\r\n  Output: w = [7\r\n               3\r\n               2\r\n               0\r\n               2]\r\n\r\n  Input:  v = []\r\n  Output: w = []\r\n","description_html":"\u003cp\u003e\u003cb\u003eWithout using loops\u003c/b\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [2\r\n             7\r\n             0\r\n             3\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput: w = [7\r\n             3\r\n             2\r\n             0\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = []\r\nOutput: w = []\r\n\u003c/pre\u003e","function_template":"function w = oddEven(v)\r\n    w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('oddEven.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('oddEven.m');\r\nloopUsed = any(strfind(filetext, 'while')) || any(strfind(filetext, 'for'));\r\nassert(~loopUsed, 'Loops are forbidden')\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [2; 7; 0; 3; 2];\r\nw_correct = [7; 3; 2; 0; 2];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [1, 0, 2, 9, 3, 8, 8, 4];\r\nw_correct = [1, 9, 3, 0, 2, 8, 8, 4];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nodd  = 2 * randi([-4, 4], 1, randi([4,10])) - 1;\r\neven = 2 * randi([-4, 4], 1, randi([4,10]));\r\nv = [even, odd];\r\nw_correct = [odd, even];\r\nassert(isequal(oddEven(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":392,"test_suite_updated_at":"2018-01-07T23:06:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T11:53:55.000Z","updated_at":"2026-02-11T19:26:16.000Z","published_at":"2018-01-07T11:53:55.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\u003eWithout using loops\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\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:  v = [1, 0, 2, 9, 3, 8, 8, 4]\\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\\n\\nInput:  v = [2\\n             7\\n             0\\n             3\\n             2]\\n\\nOutput: w = [7\\n             3\\n             2\\n             0\\n             2]\\n\\nInput:  v = []\\nOutput: w = []]]\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":44416,"title":"Sum of adjacent elements in a vector","description":"Given a vector v, return a vector s containting the sum of every two adjacent elements in the vector.\r\n\r\nEvery element s(i) contains the sum of v(i) and v(i+1).\r\n\r\nExample:\r\n\r\n v = [1, 2, 4, 4, 5, 8]\r\n s = [3, 6, 8, 9, 13]","description_html":"\u003cp\u003eGiven a vector v, return a vector s containting the sum of every two adjacent elements in the vector.\u003c/p\u003e\u003cp\u003eEvery element s(i) contains the sum of v(i) and v(i+1).\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e v = [1, 2, 4, 4, 5, 8]\r\n s = [3, 6, 8, 9, 13]\u003c/pre\u003e","function_template":"function s = summ(v)\r\n  s = 2*v;\r\nend","test_suite":"%%\r\nfiletext = fileread('summ.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = randi(10, 1, randi(10));\r\ns = summ(v);\r\nassert(length(s) == length(v) - 1)\r\n\r\n%%\r\nv = 1:10;\r\ns_correct = 3:2:19;\r\nassert(isequal(summ(v),s_correct))\r\n\r\n%%\r\nv = [1; 2; 4; 4; 5; 8];\r\ns_correct = [3; 6; 8; 9; 13];\r\nassert(isequal(summ(v),s_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":583,"test_suite_updated_at":"2017-12-03T20:37:51.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-11-26T22:53:31.000Z","updated_at":"2026-02-05T19:43:52.000Z","published_at":"2017-11-26T22:53: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 a vector v, return a vector s containting the sum of every two adjacent elements in the vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery element s(i) contains the sum of v(i) and v(i+1).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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[ v = [1, 2, 4, 4, 5, 8]\\n s = [3, 6, 8, 9, 13]]]\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":44484,"title":"Separate even from odd numbers in a vector - with a loop","description":"*Using a loop*, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\n  Output: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\r\n  Input:  v = [2\r\n               7\r\n               0\r\n               3\r\n               2]\r\n\r\n  Output: w = [7\r\n               3\r\n               2\r\n               0\r\n               2]\r\n\r\n  Input:  v = []\r\n  Output: w = []\r\n","description_html":"\u003cp\u003e\u003cb\u003eUsing a loop\u003c/b\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [2\r\n             7\r\n             0\r\n             3\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput: w = [7\r\n             3\r\n             2\r\n             0\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = []\r\nOutput: w = []\r\n\u003c/pre\u003e","function_template":"function w = oddEven(v)\r\n    w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('oddEven.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('oddEven.m');\r\nloopUsed = ~isempty(strfind(filetext, 'while')) || ~isempty(strfind(filetext, 'for'));\r\nassert(loopUsed, 'Must use at least one loop')\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [2; 7; 0; 3; 2];\r\nw_correct = [7; 3; 2; 0; 2];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [1, 0, 2, 9, 3, 8, 8, 4];\r\nw_correct = [1, 9, 3, 0, 2, 8, 8, 4];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nodd  = 2 * randi([-4, 4], 1, randi([4,10])) - 1;\r\neven = 2 * randi([-4, 4], 1, randi([4,10]));\r\nv = [even, odd];\r\nw_correct = [odd, even];\r\nassert(isequal(oddEven(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":454,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T12:16:14.000Z","updated_at":"2026-02-11T19:24:54.000Z","published_at":"2018-01-07T12:16:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eUsing a loop\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\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:  v = [1, 0, 2, 9, 3, 8, 8, 4]\\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\\n\\nInput:  v = [2\\n             7\\n             0\\n             3\\n             2]\\n\\nOutput: w = [7\\n             3\\n             2\\n             0\\n             2]\\n\\nInput:  v = []\\nOutput: w = []]]\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":44492,"title":"Approximate the cosine function ","description":"Without using MATLAB trigonometric functions, calculate the cosine of an argument x to a precision of 0.0001\r\nHint: You may wish to consider the cosine Maclaurin series.","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: 51.5px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 25.75px; transform-origin: 407px 25.75px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21.5px; 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.75px; text-align: left; transform-origin: 384px 10.75px; 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: 262px 8px; transform-origin: 262px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWithout using MATLAB trigonometric functions, calculate the cosine of an argument\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003ex\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52.5px 8px; transform-origin: 52.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e to a precision of\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 24px 8px; transform-origin: 24px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003e0.0001\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: 16px 8px; transform-origin: 16px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eHint:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 93.5px 8px; transform-origin: 93.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e You may wish to consider the\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://en.wikipedia.org/wiki/Taylor_series#Trigonometric_functions\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ecosine Maclaurin series\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = myCos(x)\r\n    y = 1 - 0.5*x^2;\r\nend","test_suite":"%%\r\nfiletext = fileread('myCos.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n\r\n%%\r\nfiletext = fileread('myCos.m');\r\ntrigUsed = any(strfind(filetext, 'cos')) || any(strfind(filetext, 'sin')) ||...\r\n     any(strfind(filetext, 'sec')) || any(strfind(filetext, 'tan')) || any(strfind(filetext, 'cot'));\r\nassert(~trigUsed, 'Cannot use MATLAB trigonometric functions')\r\n\r\n%%\r\nx = 0;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n\r\n%%\r\nx = pi;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n\r\n%%\r\nx = pi/2;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n\r\n%%\r\nx = 5*pi/3;\r\nassert(abs(myCos(x)-cos(x)) \u003c 0.0001)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":140356,"edited_by":223089,"edited_at":"2022-10-17T13:07:34.000Z","deleted_by":null,"deleted_at":null,"solvers_count":343,"test_suite_updated_at":"2022-10-17T13:07:34.000Z","rescore_all_solutions":false,"group_id":61,"created_at":"2018-01-07T23:20:12.000Z","updated_at":"2026-02-11T20:08:56.000Z","published_at":"2018-01-07T23:20:12.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\u003eWithout using MATLAB trigonometric functions, calculate the cosine of an argument\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 a precision 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\u003e0.0001\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e You may wish to consider 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=\\\"https://en.wikipedia.org/wiki/Taylor_series#Trigonometric_functions\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecosine Maclaurin series\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44455,"title":"Find the average of a random sequance","description":"Write a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\r\n\r\nAt each iteration a random integer between 0 and 10 is generated.\r\n\r\nOnly if the number is positive, it is added to the sequence.\r\n\r\nThe loop terminates when the number 0 is generated. This number is not considered for the mean.\r\n\r\n*You are not allowed to use the functions |sum()| and |mean()|*\r\n\r\nExamples:\r\n\r\n  Random sequence is: 4, 3, 5, 10, 3, 0\r\n  Output is: 5\r\n\r\n  Random sequence is: 0\r\n  Output is 0\r\n\r\n  Random sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\n  Output is: 4\r\n\r\n*Note*: the function does not have an input. The output depends on the state of the random numbers generator.","description_html":"\u003cp\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/p\u003e\u003cp\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/p\u003e\u003cp\u003eOnly if the number is positive, it is added to the sequence.\u003c/p\u003e\u003cp\u003eThe loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/p\u003e\u003cp\u003e\u003cb\u003eYou are not allowed to use the functions \u003ctt\u003esum()\u003c/tt\u003e and \u003ctt\u003emean()\u003c/tt\u003e\u003c/b\u003e\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 4, 3, 5, 10, 3, 0\r\nOutput is: 5\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 0\r\nOutput is 0\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\nOutput is: 4\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eNote\u003c/b\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\u003c/p\u003e","function_template":"function average = MeanWhile()\r\n    average = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'sum')),'sum() function is forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'mean')),'mean() function is forbidden')\r\n\r\n%%\r\nrng(1);\r\nav_correct = 5.5;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(2);\r\nav_correct = 4;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(3);\r\nav_correct = 5.25;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(7);\r\nav_correct = 0;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(0);\r\nav_correct = 6.571428571428571;\r\nassert(isequal(MeanWhile(),av_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":416,"test_suite_updated_at":"2017-12-17T07:32:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:37:19.000Z","updated_at":"2026-03-10T18:45:32.000Z","published_at":"2017-12-17T07:32:04.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eOnly if the number is positive, it is added to the sequence.\u003c/w:t\u003e\u003c/w:r\u003e\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 loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/w:t\u003e\u003c/w:r\u003e\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 are not allowed to use 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:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esum()\u003c/w:t\u003e\u003c/w:r\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:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emean()\u003c/w:t\u003e\u003c/w:r\u003e\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[Random sequence is: 4, 3, 5, 10, 3, 0\\nOutput is: 5\\n\\nRandom sequence is: 0\\nOutput is 0\\n\\nRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\\nOutput is: 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\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":44457,"title":"Triangle of numbers","description":"Create a matrix with the integers from 1 to |n| arranged in a triangular shape.\r\n\r\nEvery row |i| of the matrix contains |i| integers, and the rest of the elements are zeros.\r\n\r\nExamples:\r\n\r\n  Input:  n = 6\r\n  Output: mat = [1 0 0\r\n                 2 3 0\r\n                 4 5 6]\r\n\r\n  Input:  n = 12\r\n  Output: mat = [1  0  0  0 \r\n                 2  3  0  0 \r\n                 4  5  6  0 \r\n                 7  8  9  10\r\n                 11 12 0  0]","description_html":"\u003cp\u003eCreate a matrix with the integers from 1 to \u003ctt\u003en\u003c/tt\u003e arranged in a triangular shape.\u003c/p\u003e\u003cp\u003eEvery row \u003ctt\u003ei\u003c/tt\u003e of the matrix contains \u003ctt\u003ei\u003c/tt\u003e integers, and the rest of the elements are zeros.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 6\r\nOutput: mat = [1 0 0\r\n               2 3 0\r\n               4 5 6]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 12\r\nOutput: mat = [1  0  0  0 \r\n               2  3  0  0 \r\n               4  5  6  0 \r\n               7  8  9  10\r\n               11 12 0  0]\r\n\u003c/pre\u003e","function_template":"function mat = triangle(n)\r\n    mat = 1:n;\r\nend","test_suite":"%%\r\nfiletext = fileread('triangle.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nmat_correct = [];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 1;\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 6;\r\nmat_correct = [1 0 0; 2 3 0; 4 5 6];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 12;\r\nmat_correct = [1 0 0 0; 2 3 0 0; 4 5 6 0; 7 8 9 10; 11 12 0 0];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 50;\r\nmat_correct = [1,zeros(1,8); 2:3,zeros(1,7); 4:6,zeros(1,6);\r\n    7:10,zeros(1,5); 11:15,zeros(1,4); 16:21,zeros(1,3);\r\n    22:28,0,0; ; 29:36,0; 37:45; 46:50,zeros(1,4)];\r\nassert(isequal(triangle(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-17T08:43:23.000Z","updated_at":"2026-02-11T20:05:28.000Z","published_at":"2017-12-17T08:43:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate a matrix with the integers from 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: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 arranged in a triangular shape.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eEvery row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the matrix contains\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e integers, and the rest of the elements are zeros.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n = 6\\nOutput: mat = [1 0 0\\n               2 3 0\\n               4 5 6]\\n\\nInput:  n = 12\\nOutput: mat = [1  0  0  0 \\n               2  3  0  0 \\n               4  5  6  0 \\n               7  8  9  10\\n               11 12 0  0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":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\"}]}"}],"term":"tag:\"22105\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"22105\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"22105\"","","\"","22105","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac508f08c8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fac508f0828\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac4b34fab8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac508f0c88\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac508f0aa8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac508f0a08\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac508f0968\u003e":"tag:\"22105\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac508f0968\u003e":"tag:\"22105\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"22105\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"22105\"","","\"","22105","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac508f08c8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fac508f0828\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac4b34fab8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac508f0c88\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac508f0aa8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac508f0a08\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac508f0968\u003e":"tag:\"22105\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac508f0968\u003e":"tag:\"22105\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44401,"difficulty_rating":"easy"},{"id":44447,"difficulty_rating":"easy"},{"id":44392,"difficulty_rating":"easy"},{"id":44445,"difficulty_rating":"easy"},{"id":44437,"difficulty_rating":"easy"},{"id":44402,"difficulty_rating":"easy-medium"},{"id":44439,"difficulty_rating":"easy-medium"},{"id":44436,"difficulty_rating":"easy-medium"},{"id":44415,"difficulty_rating":"easy-medium"},{"id":44446,"difficulty_rating":"easy-medium"},{"id":44499,"difficulty_rating":"easy-medium"},{"id":44476,"difficulty_rating":"easy-medium"},{"id":44454,"difficulty_rating":"easy-medium"},{"id":44468,"difficulty_rating":"easy-medium"},{"id":44469,"difficulty_rating":"easy-medium"},{"id":44467,"difficulty_rating":"easy-medium"},{"id":44483,"difficulty_rating":"medium"},{"id":44416,"difficulty_rating":"medium"},{"id":44490,"difficulty_rating":"medium"},{"id":44484,"difficulty_rating":"medium"},{"id":44492,"difficulty_rating":"medium"},{"id":44455,"difficulty_rating":"medium"},{"id":44486,"difficulty_rating":"medium"},{"id":44457,"difficulty_rating":"medium"},{"id":44491,"difficulty_rating":"medium-hard"}]}}