{"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":314,"title":"Find the sum of the elements in the \"second\" diagonal","description":"Find the sum of the elements in the diagonal that starts at the top-right corner and ends at the bottom-left corner.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.5px; transform-origin: 407px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 355.5px 8px; transform-origin: 355.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind the sum of the elements in the diagonal that starts at the top-right corner and ends at the bottom-left corner.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = sum_of_sec_diag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(6);\r\ny_correct = 111;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx = magic(10);\r\ny_correct = 505;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=[1 2 3; 4 4 6; 2 8 9];\r\ny_correct = 9;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=[0 0 0 1;0 0 -1 0; 0 -1 0 0; 1 0 0 0];\r\ny_correct = 0;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=spiral(5)\r\ny_correct = 57;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=eye(11)\r\ny_correct = 1;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":4,"created_by":588,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1204,"test_suite_updated_at":"2021-06-21T10:13:47.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2012-02-12T12:29:12.000Z","updated_at":"2026-02-15T10:10:42.000Z","published_at":"2012-02-13T20:35:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the sum of the elements in the diagonal that starts at the top-right corner and ends at the bottom-left corner.\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":43675,"title":"Weave two matrices together to form one matrix","description":"Take the first column from matrix a, then insert the first column from matrix b, and so on. For example:\r\n\r\n a = [1 2 3 4];\r\n b = [5 6 7 8];\r\n\r\n c = [1 5 2 6 3 7 4 8];","description_html":"\u003cp\u003eTake the first column from matrix a, then insert the first column from matrix b, and so on. For example:\u003c/p\u003e\u003cpre\u003e a = [1 2 3 4];\r\n b = [5 6 7 8];\u003c/pre\u003e\u003cpre\u003e c = [1 5 2 6 3 7 4 8];\u003c/pre\u003e","function_template":"function c = merge(a,b)\r\n c = [];\r\nend","test_suite":"%%\r\na = [1 2 3 4];\r\nb = [5 6 7 8];\r\ny_correct = [1 5 2 6 3 7 4 8];\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = 1:2:10;\r\nb = 2:2:10;\r\ny_correct = 1:10;\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = ones(1,5);\r\nb = 2*ones(1,5);\r\ny_correct = repmat([1 2],[1,5]);\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = [1 2 3; 4 5 6];\r\nb = [4 5 6; 7 8 9];\r\ny_correct = [1 4 2 5 3 6; 4 7 5 8 6 9];\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = ones(3);\r\nb = eye(3);\r\ny_correct = [1 1 1 0 1 0; 1 0 1 1 1 0; 1 0 1 0 1 1];\r\nassert(isequal(merge(a,b),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":60441,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":91,"test_suite_updated_at":"2016-12-16T19:02:59.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-11-21T14:35:35.000Z","updated_at":"2026-03-29T18:43:33.000Z","published_at":"2016-11-21T14:38:51.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 the first column from matrix a, then insert the first column from matrix b, and so on. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a = [1 2 3 4];\\n b = [5 6 7 8];\\n\\n c = [1 5 2 6 3 7 4 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":42922,"title":"Zero Cross","description":"Write a function that counts the number of times n a signal x changes sign. \r\n\r\nExamples\r\n\r\n x = [1 2 -3 -4 5 6 -7 8 -9 10 11]\r\n n = 6\r\n\r\n x = [1 2 -3]\r\n n = 1","description_html":"\u003cp\u003eWrite a function that counts the number of times n a signal x changes sign.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cpre\u003e x = [1 2 -3 -4 5 6 -7 8 -9 10 11]\r\n n = 6\u003c/pre\u003e\u003cpre\u003e x = [1 2 -3]\r\n n = 1\u003c/pre\u003e","function_template":"function n = Zero_Cross(x)\r\n%Can you write a function counts the number of times(n) a signal(x) \r\n%crosses zero or changes sign.\r\n\r\n  n = x;\r\nend","test_suite":"%%\r\nx = [1 2 -3 -4 5 6 -7 8 -9 10 11];\r\nn = 6;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = [1 2 -3 ];\r\nn = 1;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = ones(1,100);\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = [-6.1 -4.2 -1.1 -6  7 -6 -6 -7  -6  -1];\r\nn = 2;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = 1\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = ones(1,50) - 25;\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = 1:50 - 25;\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = [ones(1,50); -ones(1,50)];\r\nx = reshape(x,[1,100]);\r\nn = 99;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx=[1 -1 0 4 0 -1 -2];\r\nn = 3;\r\nassert(isequal(Zero_Cross(x),n))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":2,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":134,"test_suite_updated_at":"2019-03-16T19:57:29.000Z","rescore_all_solutions":true,"group_id":43,"created_at":"2016-08-24T07:26:26.000Z","updated_at":"2026-02-04T16:10:15.000Z","published_at":"2016-08-24T07:30:50.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 counts the number of times n a signal x changes sign.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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[ x = [1 2 -3 -4 5 6 -7 8 -9 10 11]\\n n = 6\\n\\n x = [1 2 -3]\\n 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":42845,"title":"generate number in particular way","description":"   \r\n\r\n\r\n    A = [1 5 2 7];\r\n    MAX = 10;\r\n\r\n\r\n     \r\n\r\ngenerate a array \r\n\r\n    Y = [1 2 2 2 2 2 3 3 4 4];\r\n\r\ni.e. total element will be MAX in Y","description_html":"\u003cpre\u003e    A = [1 5 2 7];\r\n    MAX = 10;\u003c/pre\u003e\u003cp\u003egenerate a array\u003c/p\u003e\u003cpre\u003e    Y = [1 2 2 2 2 2 3 3 4 4];\u003c/pre\u003e\u003cp\u003ei.e. total element will be MAX in Y\u003c/p\u003e","function_template":"function y = your_fcn_name(a,m)\r\n  y = x;\r\nend","test_suite":"%%\r\na = [1 5 2 7];\r\nm = 10;\r\ny_correct = [1 2 2 2 2 2 3 3 4 4];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = [2 3 2 7 4 6];\r\nm = 22;\r\ny_correct = [1 1 2 2 2 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = ones(1,100);\r\nm = 42;\r\ny_correct = 1:42;\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = [3 1 2 6 1];\r\nm = 13;\r\ny_correct = [1 1 1 2 3 3 4 4 4 4 4 4 5];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = 1:10;\r\nm = 20;\r\ny_correct = [1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = [3 1 4 1 5 2];\r\nm = 13;\r\ny_correct = [1 1 1 2 3 3 3 3 4 5 5 5 5];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":14921,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":116,"test_suite_updated_at":"2018-05-23T12:48:50.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-05-01T20:27:39.000Z","updated_at":"2025-12-23T02:54:04.000Z","published_at":"2016-05-01T20:27: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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    A = [1 5 2 7];\\n    MAX = 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\u003egenerate a array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    Y = [1 2 2 2 2 2 3 3 4 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:t\u003ei.e. total element will be MAX in Y\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":42992,"title":"S-T-R-E-T-C-H   I-T   O-U-T","description":"You will be given a row of numbers (x), and a single number (n).  Your job is to write a script that will stretch out the row of numbers, putting n numbers between each of the numbers in x.  The numbers you put in x will be linearly interpolated.\r\n\r\nFor example, if x=[1 5 2 4 3] and n=1, your output should be:\r\n\r\ny=[1 3 5 3.5 2 3 4 3.5 3]\r\n\r\nThere is n=1 number between all of the original values of x, and the new values are linearly interpolated from the original values of x:\r\n\r\n* 1 --\u003e 3 --\u003e 5\r\n* 5 --\u003e  3.5  --\u003e 2\r\n* 2 --\u003e 3 --\u003e 4\r\n* 4 --\u003e 3.5 --\u003e 3","description_html":"\u003cp\u003eYou will be given a row of numbers (x), and a single number (n).  Your job is to write a script that will stretch out the row of numbers, putting n numbers between each of the numbers in x.  The numbers you put in x will be linearly interpolated.\u003c/p\u003e\u003cp\u003eFor example, if x=[1 5 2 4 3] and n=1, your output should be:\u003c/p\u003e\u003cp\u003ey=[1 3 5 3.5 2 3 4 3.5 3]\u003c/p\u003e\u003cp\u003eThere is n=1 number between all of the original values of x, and the new values are linearly interpolated from the original values of x:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 --\u0026gt; 3 --\u0026gt; 5\u003c/li\u003e\u003cli\u003e5 --\u0026gt;  3.5  --\u0026gt; 2\u003c/li\u003e\u003cli\u003e2 --\u0026gt; 3 --\u0026gt; 4\u003c/li\u003e\u003cli\u003e4 --\u0026gt; 3.5 --\u0026gt; 3\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = stretch_it_out(x,n)\r\n  y = x.*n;\r\nend","test_suite":"%%\r\nx = [1 5 2 4 3];n=1;\r\ny_correct = [1 3 5 3.5 2 3 4 3.5 3];\r\nassert(isequal(stretch_it_out(x,n),y_correct))\r\n%%\r\nx = [1 5 2 4 3];n=2;\r\ny_correct=[1 2+1/3 3+2/3 5 4 3 2 2+2/3 3+1/3 4 3+2/3 3+1/3 3];\r\ny=abs(stretch_it_out(x,n)-y_correct);\r\nassert(max(y)\u003c1e-9)\r\n%%\r\nk=ceil(5*rand)+1\r\nx=1:k:121\r\nn=k-1;\r\nassert(isequal(stretch_it_out(x,n),1:121))\r\n%%\r\nx=[1 -1 1 -1 1 -1 1];n=3;\r\ny_correct=[1 0.5  0 -0.5 -1 -0.5  0 0.5  1 0.5  0 -0.5 -1 -0.5  0 0.5  1 0.5  0 -0.5 -1 -0.5  0 0.5  1];\r\nassert(isequal(stretch_it_out(x,n),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-09-20T17:08:32.000Z","updated_at":"2025-12-23T03:42:27.000Z","published_at":"2016-09-20T17:09: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\u003eYou will be given a row of numbers (x), and a single number (n). Your job is to write a script that will stretch out the row of numbers, putting n numbers between each of the numbers in x. The numbers you put in x will be linearly interpolated.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if x=[1 5 2 4 3] and n=1, your output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey=[1 3 5 3.5 2 3 4 3.5 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere is n=1 number between all of the original values of x, and the new values are linearly interpolated from the original values of x:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 --\u0026gt; 3 --\u0026gt; 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5 --\u0026gt; 3.5 --\u0026gt; 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2 --\u0026gt; 3 --\u0026gt; 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4 --\u0026gt; 3.5 --\u0026gt; 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43072,"title":"Check if a rotated array was originally sorted","description":"Suppose a sorted array is rotated at some pivot unknown to you. For example, |[0 1 2 4 5 6 7]|  might become |[5 6 7 0 1 2 4]|.\r\n\r\nGiven a rotated array, find out if it was originally sorted. Your function will return *true* for this array: |[4 5 6 7 0 1 2]|. But it will return *false* for |[2 5 6 8 0 1 3]|, because its original array, i.e.,  |[0 1 3 2 5 6 8]|, was not sorted.","description_html":"\u003cp\u003eSuppose a sorted array is rotated at some pivot unknown to you. For example, \u003ctt\u003e[0 1 2 4 5 6 7]\u003c/tt\u003e  might become \u003ctt\u003e[5 6 7 0 1 2 4]\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eGiven a rotated array, find out if it was originally sorted. Your function will return \u003cb\u003etrue\u003c/b\u003e for this array: \u003ctt\u003e[4 5 6 7 0 1 2]\u003c/tt\u003e. But it will return \u003cb\u003efalse\u003c/b\u003e for \u003ctt\u003e[2 5 6 8 0 1 3]\u003c/tt\u003e, because its original array, i.e.,  \u003ctt\u003e[0 1 3 2 5 6 8]\u003c/tt\u003e, was not sorted.\u003c/p\u003e","function_template":"function y = isRotaSorTED(x)\r\n  y = true;\r\nend","test_suite":"%%\r\nx = [4 5 6 7 0 1 2];\r\ny_correct = true;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = [2 5 6 8 0 1 3];\r\ny_correct = false;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = [101, 103, 106, 109, 158, 164, 182, 187, 202, 205, 2, 3, 32, 57, 69, 74, 81, 99, 100];\r\ny_correct = true;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = [42 1:10];\r\ny_correct = true;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\nx(1) = 100; x(4) = 1;\r\ny_correct = false;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = 10:-1:1;\r\ny_correct = false;\r\nassert(isequal(isRotaSorTED(x),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":25354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":80,"test_suite_updated_at":"2018-05-23T13:13:55.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-10-05T19:43:37.000Z","updated_at":"2025-12-23T03:42:59.000Z","published_at":"2016-10-05T19:43: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\u003eSuppose a sorted array is rotated at some pivot unknown to you. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[0 1 2 4 5 6 7]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e might become\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[5 6 7 0 1 2 4]\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\u003eGiven a rotated array, find out if it was originally sorted. Your function will return\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003etrue\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for this array:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[4 5 6 7 0 1 2]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. But it will return\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efalse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2 5 6 8 0 1 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, because its original array, i.e., \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[0 1 3 2 5 6 8]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, was not sorted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42893,"title":"Look Up Mapping","description":"Let the input is \r\n\r\nA = {[] [] [] [1] []};\r\n\r\nB = {'A','B','C','D','E'};\r\n\r\nMapped Output = 'D';","description_html":"\u003cp\u003eLet the input is\u003c/p\u003e\u003cp\u003eA = {[] [] [] [1] []};\u003c/p\u003e\u003cp\u003eB = {'A','B','C','D','E'};\u003c/p\u003e\u003cp\u003eMapped Output = 'D';\u003c/p\u003e","function_template":"function y = Mapp_It(A,B)\r\n  y = [];\r\nend","test_suite":"%%\r\nA = {[] [] [] [1] []};\r\nB = {'A','B','C','D','E'};\r\ny_correct = 'D';\r\nassert(isequal(Mapp_It(A,B),y_correct))\r\n\r\n\r\n%%\r\nA = {[] [] [] [1]; [] [1] [] []};\r\nB = {'A','B','C','D'};\r\ny_correct = {'D';'B'};\r\nassert(isequal(Mapp_It(A,B),y_correct))\r\n\r\n%%\r\nA = {[] [] [1]; [] [1] [];  [1] [] []};\r\nB = {'A','B','C'};\r\ny_correct = {'C';'B';'A'};\r\nassert(isequal(Mapp_It(A,B),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":25856,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-06-17T10:11:17.000Z","updated_at":"2025-12-23T02:55:41.000Z","published_at":"2016-06-17T10:11:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet the input is\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA = {[] [] [] [1] []};\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eB = {'A','B','C','D','E'};\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMapped Output = 'D';\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":42809,"title":"Sorting integers by their digits (Level 1)","description":"Given a vector, v, of positive integers, return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nExample:\r\n\r\nv = [14 3 268 14 210 1 80];\r\n\r\nw = [1 14 14 210 268 3 80];\r\n\r\nAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.","description_html":"\u003cp\u003eGiven a vector, v, of positive integers, return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14 3 268 14 210 1 80];\u003c/p\u003e\u003cp\u003ew = [1 14 14 210 268 3 80];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14 3 268 14 210 1 80];\r\nw_correct = [1 14 14 210 268 3 80];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [246 24680 2468 246 24 2 24680 24 2468 2];\r\nw_correct = [2 2 24 24 246 246 2468 2468 24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-19T20:04:25.000Z","updated_at":"2026-03-16T16:49:45.000Z","published_at":"2016-04-19T20:04:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of positive integers, return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14 3 268 14 210 1 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [1 14 14 210 268 3 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\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":42815,"title":"Sorting integers by their digits (Level 3)","description":"This is the next step up from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42811-sorting-integers-by-their-digits-level-2 Problem 42811\u003e.\r\n\r\nGiven a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nExample:\r\n\r\nv = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\r\n\r\nw = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\r\n\r\nAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\r\n\r\nNegative numbers take precedence over positive numbers.","description_html":"\u003cp\u003eThis is the next step up from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42811-sorting-integers-by-their-digits-level-2\"\u003eProblem 42811\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\u003c/p\u003e\u003cp\u003ew = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/p\u003e\u003cp\u003eNegative numbers take precedence over positive numbers.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\r\nw_correct = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-246 -24680 2468 246 24 -2 24680 -24 -2468 2];\r\nw_correct = [-2 2 -24 24 -246 246 -2468 2468 -24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-0.22222 0.22 0.222 0.2 0.2222];\r\nw_correct = [0.2 0.22 0.222 0.2222 -0.22222];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-20T19:57:51.000Z","updated_at":"2026-03-12T02:58:05.000Z","published_at":"2016-04-20T19:57:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the next step up from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42811-sorting-integers-by-their-digits-level-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42811\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNegative numbers take precedence over positive numbers.\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":42894,"title":"Find longest run","description":"Write a function longest_run that takes as input an array of 0's and 1's and outputs the length and index of the longest consecutive run of either 0's or 1's. If there are multiple runs of the same length, it should output the first occurence.\r\n\r\nExamples:\r\n\r\n1. |longest_run([1 1 0 1])| should output |[2 1]|,\r\nsince the longest consecutive run is 11, which starts at index 1\r\n\r\n2. |longest_run([1 1 0 1 0 0 0 0 1 1 1])| should ouptut |[4 5]|,\r\nsince the longest consecutive run is 0000, which starts at index 5\r\n\r\n3. |longest_run([1 0])| should ouptut |[1 1]|,\r\nsince the _first_ longest consecutive run is 1, which starts at index 1","description_html":"\u003cp\u003eWrite a function longest_run that takes as input an array of 0's and 1's and outputs the length and index of the longest consecutive run of either 0's or 1's. If there are multiple runs of the same length, it should output the first occurence.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cp\u003e1. \u003ctt\u003elongest_run([1 1 0 1])\u003c/tt\u003e should output \u003ctt\u003e[2 1]\u003c/tt\u003e,\r\nsince the longest consecutive run is 11, which starts at index 1\u003c/p\u003e\u003cp\u003e2. \u003ctt\u003elongest_run([1 1 0 1 0 0 0 0 1 1 1])\u003c/tt\u003e should ouptut \u003ctt\u003e[4 5]\u003c/tt\u003e,\r\nsince the longest consecutive run is 0000, which starts at index 5\u003c/p\u003e\u003cp\u003e3. \u003ctt\u003elongest_run([1 0])\u003c/tt\u003e should ouptut \u003ctt\u003e[1 1]\u003c/tt\u003e,\r\nsince the \u003ci\u003efirst\u003c/i\u003e longest consecutive run is 1, which starts at index 1\u003c/p\u003e","function_template":"function [run_length, start_index] = longest_run(binary_array)\r\n%longest_run Finds longest consecutive runs of zeros or ones\r\n%   run_length is the length of the longest run of zeros or ones\r\n%   start_index is the index where the run begins\r\n\r\n    run_length = 1;\r\n    start_index = 1;\r\nend","test_suite":"%%\r\nbinary_array = [1 1 0 1];\r\nexpected_length = 2;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1 1 0 1 0 0 0 0 1 1 1];\r\nexpected_length = 4;\r\nexpected_index = 5;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1 0];\r\nexpected_length = 1;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1];\r\nexpected_length = 1;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1 1 1 1 1 1];\r\nexpected_length = 6;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":26948,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":88,"test_suite_updated_at":"2016-06-29T20:27:09.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-06-29T18:38:46.000Z","updated_at":"2026-01-12T14:18:11.000Z","published_at":"2016-06-29T20:27: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\u003eWrite a function longest_run that takes as input an array of 0's and 1's and outputs the length and index of the longest consecutive run of either 0's or 1's. If there are multiple runs of the same length, it should output the first occurence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elongest_run([1 1 0 1])\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should output\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, since the longest consecutive run is 11, which starts at index 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\u003e2.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elongest_run([1 1 0 1 0 0 0 0 1 1 1])\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should ouptut\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[4 5]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, since the longest consecutive run is 0000, which starts at index 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elongest_run([1 0])\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should ouptut\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[1 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, since 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efirst\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e longest consecutive run is 1, which starts at index 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42811,"title":"Sorting integers by their digits (Level 2)","description":"This is the next step up from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42809-sorting-integers-by-their-digits Problem 42809\u003e.\r\n\r\nGiven a vector, v, of integers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nExample:\r\n\r\nv = [14 3 268 -14 210 1 80];\r\n\r\nw = [1 -14 14 210 268 3 80];\r\n\r\nAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\r\n\r\nNegative integers take precedence over positive integers.","description_html":"\u003cp\u003eThis is the next step up from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42809-sorting-integers-by-their-digits\"\u003eProblem 42809\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a vector, v, of integers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14 3 268 -14 210 1 80];\u003c/p\u003e\u003cp\u003ew = [1 -14 14 210 268 3 80];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\u003c/p\u003e\u003cp\u003eNegative integers take precedence over positive integers.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14 3 268 -14 210 1 80];\r\nw_correct = [1 -14 14 210 268 3 80];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-246 -24680 2468 246 24 -2 24680 -24 -2468 2];\r\nw_correct = [-2 2 -24 24 -246 246 -2468 2468 -24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-20T04:50:21.000Z","updated_at":"2026-03-12T02:54:13.000Z","published_at":"2016-04-20T04:50:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the next step up from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42809-sorting-integers-by-their-digits\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42809\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of integers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14 3 268 -14 210 1 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [1 -14 14 210 268 3 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNegative integers take precedence over positive integers.\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":340,"title":"Find last non-zero in a given dimension","description":"You are given a logical matrix *BW* _of any dimension_, and a dimension *dim*. You need to find the locations of the last non-zero element of *BW* in that given dimension. If no non-zeros exist at an element location, return a *0* at that location.\r\n\r\nFor example, given:\r\n\r\n  BW = [0 0 0 0; 1 1 1 1; 0 1 1 0]\r\n\r\nWhen dim = 1, you should return:\r\n\r\nans = [2 3 3 2], because these are the row numbers of the last non-zeroes in each column.\r\n\r\nWhen dim = 2, you should return:\r\n\r\nans = [0; 4; 3], because these are the column numbers of the last non-zeroes in each row.\r\n\r\nDon't forget that the input isn't restricted to 2D matrices.","description_html":"\u003cp\u003eYou are given a logical matrix \u003cb\u003eBW\u003c/b\u003e \u003ci\u003eof any dimension\u003c/i\u003e, and a dimension \u003cb\u003edim\u003c/b\u003e. You need to find the locations of the last non-zero element of \u003cb\u003eBW\u003c/b\u003e in that given dimension. If no non-zeros exist at an element location, return a \u003cb\u003e0\u003c/b\u003e at that location.\u003c/p\u003e\u003cp\u003eFor example, given:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eBW = [0 0 0 0; 1 1 1 1; 0 1 1 0]\r\n\u003c/pre\u003e\u003cp\u003eWhen dim = 1, you should return:\u003c/p\u003e\u003cp\u003eans = [2 3 3 2], because these are the row numbers of the last non-zeroes in each column.\u003c/p\u003e\u003cp\u003eWhen dim = 2, you should return:\u003c/p\u003e\u003cp\u003eans = [0; 4; 3], because these are the column numbers of the last non-zeroes in each row.\u003c/p\u003e\u003cp\u003eDon't forget that the input isn't restricted to 2D matrices.\u003c/p\u003e","function_template":"function out = findlastindim(BW,dim)\r\n  out = BW;\r\nend","test_suite":"%% Test the examples\r\nBW = [0 0 0 0; 1 1 1 1; 0 1 1 0];\r\nout_correct = [2 3 3 2];\r\nassert(isequal(findlastindim(BW,1),out_correct))\r\nout_correct = [0; 4; 3];\r\nassert(isequal(findlastindim(BW,2),out_correct))\r\n\r\n%% Test some different matrices\r\nBW = eye(10);\r\nout_correct = 1:10;\r\nassert(isequal(findlastindim(BW,1),out_correct))\r\nassert(isequal(findlastindim(BW,2),out_correct'))\r\n\r\n%% Test some different dimensions (and prevent hard-coded solutions)\r\nBW = rand(10)\u003e0.5;\r\nassert(isequal(findlastindim(BW,3),BW))\r\nassert(isequal(findlastindim(BW,4),BW))\r\n\r\n%% Test something in the 3rd dimension that is small enough to visualise.\r\nBW = cat(3, eye(5), fliplr(eye(5)));\r\nout_correct = [1     0     0     0     2\r\n     0     1     0     2     0\r\n     0     0     2     0     0\r\n     0     2     0     1     0\r\n     2     0     0     0     1];\r\nassert(isequal(findlastindim(BW,3),out_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":1101,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":49,"test_suite_updated_at":"2012-02-19T01:16:55.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2012-02-19T00:58:31.000Z","updated_at":"2026-01-06T07:39:02.000Z","published_at":"2012-02-19T01:17: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:t\u003eYou are given a logical matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eBW\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eof any dimension\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and a dimension\u003c/w:t\u003e\u003c/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\u003edim\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. You need to find the locations of the last non-zero element of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eBW\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in that given dimension. If no non-zeros exist at an element location, return a\u003c/w:t\u003e\u003c/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\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e at that location.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, given:\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[BW = [0 0 0 0; 1 1 1 1; 0 1 1 0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhen dim = 1, you should return:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eans = [2 3 3 2], because these are the row numbers of the last non-zeroes in each 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:t\u003eWhen dim = 2, you should return:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eans = [0; 4; 3], because these are the column numbers of the last non-zeroes in each row.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDon't forget that the input isn't restricted to 2D matrices.\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":42875,"title":"Assignment Problem","description":"Given a matrix where row i corresponds to person i, and column j corresponds to task j and cell (i,j) corresponds to the time taken for person i to complete task j. Output an assignment array for the minimal time taken for all tasks.\r\n\r\nFor example, if presented with the following matrix:\r\n\r\n x = [1,3,4,7;  \r\n      2,3,1,3;\r\n      4,2,3,7;\r\n      6,4,2,2;]\r\n\r\nYour output array would be:\r\n\r\n a = [1,3,2,4].\r\n\r\nWhere person one is assigned to task one, person three is assigned to task two , person two is assigned to task three and person four is assigned to task four.\r\n\r\nThis gives us a total time of 1+1+2+2=6 which is minimal.","description_html":"\u003cp\u003eGiven a matrix where row i corresponds to person i, and column j corresponds to task j and cell (i,j) corresponds to the time taken for person i to complete task j. Output an assignment array for the minimal time taken for all tasks.\u003c/p\u003e\u003cp\u003eFor example, if presented with the following matrix:\u003c/p\u003e\u003cpre\u003e x = [1,3,4,7;  \r\n      2,3,1,3;\r\n      4,2,3,7;\r\n      6,4,2,2;]\u003c/pre\u003e\u003cp\u003eYour output array would be:\u003c/p\u003e\u003cpre\u003e a = [1,3,2,4].\u003c/pre\u003e\u003cp\u003eWhere person one is assigned to task one, person three is assigned to task two , person two is assigned to task three and person four is assigned to task four.\u003c/p\u003e\u003cp\u003eThis gives us a total time of 1+1+2+2=6 which is minimal.\u003c/p\u003e","function_template":"function y = Assignment(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [2,12,8,5; 4,4,5,12; 3,10,8,3; 12,0,1,2];\r\ny_correct1 = [1,2,4,3];\r\ny_correct2 = [1,4,2,3];\r\ntest1 = isequal(Assignment(x),y_correct1);\r\ntest2 = isequal(Assignment(x),y_correct2);\r\nassert(test1||test2)\r\n\r\n%%\r\nx = [7,5,3,2,6; 6,3,6,6,5; 3,3,9,4,7; 4,5,3,3,4; 2,3,4,3,5];\r\ny_correct = [5,3,4,1,2];\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\nx(x==0) = 3;\r\ny_correct = 1:4;\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = 5 * ones(5);\r\nx(1,4) = 1;\r\nx(2,2) = 1;\r\nx(3,5) = 1;\r\nx(4,1) = 1;\r\nx(5,3) = 1;\r\ny_correct = [4,2,5,1,3];\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = 1:4;\r\nx = [x; circshift(x,1); circshift(x,2); circshift(x,3)];\r\ny_correct = 1:4;\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = [7,5,4; 14,16,2; 7,1,9];\r\ny_correct = [1,3,2];\r\nassert(isequal(Assignment(x),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":6,"created_by":64486,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":"2018-07-30T13:18:15.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-06-02T23:08:15.000Z","updated_at":"2026-03-11T23:46:24.000Z","published_at":"2016-06-02T23:18:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix where row i corresponds to person i, and column j corresponds to task j and cell (i,j) corresponds to the time taken for person i to complete task j. Output an assignment array for the minimal time taken for all tasks.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if presented with the following matrix:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [1,3,4,7;  \\n      2,3,1,3;\\n      4,2,3,7;\\n      6,4,2,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\u003eYour output array would be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a = [1,3,2,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:t\u003eWhere person one is assigned to task one, person three is assigned to task two , person two is assigned to task three and person four is assigned to task four.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis gives us a total time of 1+1+2+2=6 which is minimal.\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":42816,"title":"Sorting integers by their digits (Level 4)","description":"This is the next step up from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42815-sorting-integers-by-their-digits-level-3 Problem 42815\u003e.\r\n\r\nGiven a vector, v, of complex numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nOnce all real digits have been used for sorting, it should continue with the imaginary part, which are further down the order.\r\n\r\nExample:\r\n\r\nv = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\r\n\r\nw = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\r\n\r\nAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\r\n\r\nNegative numbers take precedence over positive numbers.\r\n\r\nImaginary numbers should be treated as if they had a leading zero, because they have a zero real part.","description_html":"\u003cp\u003eThis is the next step up from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42815-sorting-integers-by-their-digits-level-3\"\u003eProblem 42815\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a vector, v, of complex numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eOnce all real digits have been used for sorting, it should continue with the imaginary part, which are further down the order.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\u003c/p\u003e\u003cp\u003ew = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/p\u003e\u003cp\u003eNegative numbers take precedence over positive numbers.\u003c/p\u003e\u003cp\u003eImaginary numbers should be treated as if they had a leading zero, because they have a zero real part.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\r\nw_correct = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-246 -24680 2468 246 24 -2 24680 -24 -2468 2];\r\nw_correct = [-2 2 -24 24 -246 246 -2468 2468 -24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-0.22222 0.22 0.222 0.2 0.2222];\r\nw_correct = [0.2 0.22 0.222 0.2222 -0.22222];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-6.28 4-12i 4.01+12i 4-13i 4+13i 4+14.9i 0-75i 0+391i 4-148i];\r\nw_correct = [0+391i 0-75i 4-12i 4-13i 4+13i 4-148i 4+14.9i 4.01+12i -6.28];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":3,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-20T20:15:04.000Z","updated_at":"2026-03-12T21:55:39.000Z","published_at":"2016-04-20T20:15: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\u003eThis is the next step up from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42815-sorting-integers-by-their-digits-level-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42815\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of complex numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnce all real digits have been used for sorting, it should continue with the imaginary part, which are further down the 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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNegative numbers take precedence over positive numbers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImaginary numbers should be treated as if they had a leading zero, because they have a zero real part.\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":314,"title":"Find the sum of the elements in the \"second\" diagonal","description":"Find the sum of the elements in the diagonal that starts at the top-right corner and ends at the bottom-left corner.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.5px; transform-origin: 407px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 355.5px 8px; transform-origin: 355.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind the sum of the elements in the diagonal that starts at the top-right corner and ends at the bottom-left corner.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = sum_of_sec_diag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(6);\r\ny_correct = 111;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx = magic(10);\r\ny_correct = 505;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=[1 2 3; 4 4 6; 2 8 9];\r\ny_correct = 9;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=[0 0 0 1;0 0 -1 0; 0 -1 0 0; 1 0 0 0];\r\ny_correct = 0;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=spiral(5)\r\ny_correct = 57;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))\r\n\r\n%%\r\nx=eye(11)\r\ny_correct = 1;\r\nassert(isequal(sum_of_sec_diag(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":4,"created_by":588,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1204,"test_suite_updated_at":"2021-06-21T10:13:47.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2012-02-12T12:29:12.000Z","updated_at":"2026-02-15T10:10:42.000Z","published_at":"2012-02-13T20:35:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the sum of the elements in the diagonal that starts at the top-right corner and ends at the bottom-left corner.\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":43675,"title":"Weave two matrices together to form one matrix","description":"Take the first column from matrix a, then insert the first column from matrix b, and so on. For example:\r\n\r\n a = [1 2 3 4];\r\n b = [5 6 7 8];\r\n\r\n c = [1 5 2 6 3 7 4 8];","description_html":"\u003cp\u003eTake the first column from matrix a, then insert the first column from matrix b, and so on. For example:\u003c/p\u003e\u003cpre\u003e a = [1 2 3 4];\r\n b = [5 6 7 8];\u003c/pre\u003e\u003cpre\u003e c = [1 5 2 6 3 7 4 8];\u003c/pre\u003e","function_template":"function c = merge(a,b)\r\n c = [];\r\nend","test_suite":"%%\r\na = [1 2 3 4];\r\nb = [5 6 7 8];\r\ny_correct = [1 5 2 6 3 7 4 8];\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = 1:2:10;\r\nb = 2:2:10;\r\ny_correct = 1:10;\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = ones(1,5);\r\nb = 2*ones(1,5);\r\ny_correct = repmat([1 2],[1,5]);\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = [1 2 3; 4 5 6];\r\nb = [4 5 6; 7 8 9];\r\ny_correct = [1 4 2 5 3 6; 4 7 5 8 6 9];\r\nassert(isequal(merge(a,b),y_correct))\r\n\r\n%%\r\na = ones(3);\r\nb = eye(3);\r\ny_correct = [1 1 1 0 1 0; 1 0 1 1 1 0; 1 0 1 0 1 1];\r\nassert(isequal(merge(a,b),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":60441,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":91,"test_suite_updated_at":"2016-12-16T19:02:59.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-11-21T14:35:35.000Z","updated_at":"2026-03-29T18:43:33.000Z","published_at":"2016-11-21T14:38:51.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 the first column from matrix a, then insert the first column from matrix b, and so on. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a = [1 2 3 4];\\n b = [5 6 7 8];\\n\\n c = [1 5 2 6 3 7 4 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":42922,"title":"Zero Cross","description":"Write a function that counts the number of times n a signal x changes sign. \r\n\r\nExamples\r\n\r\n x = [1 2 -3 -4 5 6 -7 8 -9 10 11]\r\n n = 6\r\n\r\n x = [1 2 -3]\r\n n = 1","description_html":"\u003cp\u003eWrite a function that counts the number of times n a signal x changes sign.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cpre\u003e x = [1 2 -3 -4 5 6 -7 8 -9 10 11]\r\n n = 6\u003c/pre\u003e\u003cpre\u003e x = [1 2 -3]\r\n n = 1\u003c/pre\u003e","function_template":"function n = Zero_Cross(x)\r\n%Can you write a function counts the number of times(n) a signal(x) \r\n%crosses zero or changes sign.\r\n\r\n  n = x;\r\nend","test_suite":"%%\r\nx = [1 2 -3 -4 5 6 -7 8 -9 10 11];\r\nn = 6;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = [1 2 -3 ];\r\nn = 1;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = ones(1,100);\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = [-6.1 -4.2 -1.1 -6  7 -6 -6 -7  -6  -1];\r\nn = 2;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = 1\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = ones(1,50) - 25;\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = 1:50 - 25;\r\nn = 0;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx = [ones(1,50); -ones(1,50)];\r\nx = reshape(x,[1,100]);\r\nn = 99;\r\nassert(isequal(Zero_Cross(x),n))\r\n\r\n%%\r\nx=[1 -1 0 4 0 -1 -2];\r\nn = 3;\r\nassert(isequal(Zero_Cross(x),n))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":2,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":134,"test_suite_updated_at":"2019-03-16T19:57:29.000Z","rescore_all_solutions":true,"group_id":43,"created_at":"2016-08-24T07:26:26.000Z","updated_at":"2026-02-04T16:10:15.000Z","published_at":"2016-08-24T07:30:50.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 counts the number of times n a signal x changes sign.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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[ x = [1 2 -3 -4 5 6 -7 8 -9 10 11]\\n n = 6\\n\\n x = [1 2 -3]\\n 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":42845,"title":"generate number in particular way","description":"   \r\n\r\n\r\n    A = [1 5 2 7];\r\n    MAX = 10;\r\n\r\n\r\n     \r\n\r\ngenerate a array \r\n\r\n    Y = [1 2 2 2 2 2 3 3 4 4];\r\n\r\ni.e. total element will be MAX in Y","description_html":"\u003cpre\u003e    A = [1 5 2 7];\r\n    MAX = 10;\u003c/pre\u003e\u003cp\u003egenerate a array\u003c/p\u003e\u003cpre\u003e    Y = [1 2 2 2 2 2 3 3 4 4];\u003c/pre\u003e\u003cp\u003ei.e. total element will be MAX in Y\u003c/p\u003e","function_template":"function y = your_fcn_name(a,m)\r\n  y = x;\r\nend","test_suite":"%%\r\na = [1 5 2 7];\r\nm = 10;\r\ny_correct = [1 2 2 2 2 2 3 3 4 4];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = [2 3 2 7 4 6];\r\nm = 22;\r\ny_correct = [1 1 2 2 2 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = ones(1,100);\r\nm = 42;\r\ny_correct = 1:42;\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = [3 1 2 6 1];\r\nm = 13;\r\ny_correct = [1 1 1 2 3 3 4 4 4 4 4 4 5];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = 1:10;\r\nm = 20;\r\ny_correct = [1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))\r\n\r\n%%\r\na = [3 1 4 1 5 2];\r\nm = 13;\r\ny_correct = [1 1 1 2 3 3 3 3 4 5 5 5 5];\r\n\r\nassert(isequal(your_fcn_name(a,m),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":14921,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":116,"test_suite_updated_at":"2018-05-23T12:48:50.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-05-01T20:27:39.000Z","updated_at":"2025-12-23T02:54:04.000Z","published_at":"2016-05-01T20:27: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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    A = [1 5 2 7];\\n    MAX = 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\u003egenerate a array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    Y = [1 2 2 2 2 2 3 3 4 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:t\u003ei.e. total element will be MAX in Y\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":42992,"title":"S-T-R-E-T-C-H   I-T   O-U-T","description":"You will be given a row of numbers (x), and a single number (n).  Your job is to write a script that will stretch out the row of numbers, putting n numbers between each of the numbers in x.  The numbers you put in x will be linearly interpolated.\r\n\r\nFor example, if x=[1 5 2 4 3] and n=1, your output should be:\r\n\r\ny=[1 3 5 3.5 2 3 4 3.5 3]\r\n\r\nThere is n=1 number between all of the original values of x, and the new values are linearly interpolated from the original values of x:\r\n\r\n* 1 --\u003e 3 --\u003e 5\r\n* 5 --\u003e  3.5  --\u003e 2\r\n* 2 --\u003e 3 --\u003e 4\r\n* 4 --\u003e 3.5 --\u003e 3","description_html":"\u003cp\u003eYou will be given a row of numbers (x), and a single number (n).  Your job is to write a script that will stretch out the row of numbers, putting n numbers between each of the numbers in x.  The numbers you put in x will be linearly interpolated.\u003c/p\u003e\u003cp\u003eFor example, if x=[1 5 2 4 3] and n=1, your output should be:\u003c/p\u003e\u003cp\u003ey=[1 3 5 3.5 2 3 4 3.5 3]\u003c/p\u003e\u003cp\u003eThere is n=1 number between all of the original values of x, and the new values are linearly interpolated from the original values of x:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 --\u0026gt; 3 --\u0026gt; 5\u003c/li\u003e\u003cli\u003e5 --\u0026gt;  3.5  --\u0026gt; 2\u003c/li\u003e\u003cli\u003e2 --\u0026gt; 3 --\u0026gt; 4\u003c/li\u003e\u003cli\u003e4 --\u0026gt; 3.5 --\u0026gt; 3\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = stretch_it_out(x,n)\r\n  y = x.*n;\r\nend","test_suite":"%%\r\nx = [1 5 2 4 3];n=1;\r\ny_correct = [1 3 5 3.5 2 3 4 3.5 3];\r\nassert(isequal(stretch_it_out(x,n),y_correct))\r\n%%\r\nx = [1 5 2 4 3];n=2;\r\ny_correct=[1 2+1/3 3+2/3 5 4 3 2 2+2/3 3+1/3 4 3+2/3 3+1/3 3];\r\ny=abs(stretch_it_out(x,n)-y_correct);\r\nassert(max(y)\u003c1e-9)\r\n%%\r\nk=ceil(5*rand)+1\r\nx=1:k:121\r\nn=k-1;\r\nassert(isequal(stretch_it_out(x,n),1:121))\r\n%%\r\nx=[1 -1 1 -1 1 -1 1];n=3;\r\ny_correct=[1 0.5  0 -0.5 -1 -0.5  0 0.5  1 0.5  0 -0.5 -1 -0.5  0 0.5  1 0.5  0 -0.5 -1 -0.5  0 0.5  1];\r\nassert(isequal(stretch_it_out(x,n),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-09-20T17:08:32.000Z","updated_at":"2025-12-23T03:42:27.000Z","published_at":"2016-09-20T17:09: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\u003eYou will be given a row of numbers (x), and a single number (n). Your job is to write a script that will stretch out the row of numbers, putting n numbers between each of the numbers in x. The numbers you put in x will be linearly interpolated.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if x=[1 5 2 4 3] and n=1, your output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey=[1 3 5 3.5 2 3 4 3.5 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere is n=1 number between all of the original values of x, and the new values are linearly interpolated from the original values of x:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 --\u0026gt; 3 --\u0026gt; 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5 --\u0026gt; 3.5 --\u0026gt; 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2 --\u0026gt; 3 --\u0026gt; 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4 --\u0026gt; 3.5 --\u0026gt; 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43072,"title":"Check if a rotated array was originally sorted","description":"Suppose a sorted array is rotated at some pivot unknown to you. For example, |[0 1 2 4 5 6 7]|  might become |[5 6 7 0 1 2 4]|.\r\n\r\nGiven a rotated array, find out if it was originally sorted. Your function will return *true* for this array: |[4 5 6 7 0 1 2]|. But it will return *false* for |[2 5 6 8 0 1 3]|, because its original array, i.e.,  |[0 1 3 2 5 6 8]|, was not sorted.","description_html":"\u003cp\u003eSuppose a sorted array is rotated at some pivot unknown to you. For example, \u003ctt\u003e[0 1 2 4 5 6 7]\u003c/tt\u003e  might become \u003ctt\u003e[5 6 7 0 1 2 4]\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eGiven a rotated array, find out if it was originally sorted. Your function will return \u003cb\u003etrue\u003c/b\u003e for this array: \u003ctt\u003e[4 5 6 7 0 1 2]\u003c/tt\u003e. But it will return \u003cb\u003efalse\u003c/b\u003e for \u003ctt\u003e[2 5 6 8 0 1 3]\u003c/tt\u003e, because its original array, i.e.,  \u003ctt\u003e[0 1 3 2 5 6 8]\u003c/tt\u003e, was not sorted.\u003c/p\u003e","function_template":"function y = isRotaSorTED(x)\r\n  y = true;\r\nend","test_suite":"%%\r\nx = [4 5 6 7 0 1 2];\r\ny_correct = true;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = [2 5 6 8 0 1 3];\r\ny_correct = false;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = [101, 103, 106, 109, 158, 164, 182, 187, 202, 205, 2, 3, 32, 57, 69, 74, 81, 99, 100];\r\ny_correct = true;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = [42 1:10];\r\ny_correct = true;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\nx(1) = 100; x(4) = 1;\r\ny_correct = false;\r\nassert(isequal(isRotaSorTED(x),y_correct))\r\n\r\n%%\r\nx = 10:-1:1;\r\ny_correct = false;\r\nassert(isequal(isRotaSorTED(x),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":25354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":80,"test_suite_updated_at":"2018-05-23T13:13:55.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-10-05T19:43:37.000Z","updated_at":"2025-12-23T03:42:59.000Z","published_at":"2016-10-05T19:43: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\u003eSuppose a sorted array is rotated at some pivot unknown to you. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[0 1 2 4 5 6 7]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e might become\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[5 6 7 0 1 2 4]\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\u003eGiven a rotated array, find out if it was originally sorted. Your function will return\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003etrue\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for this array:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[4 5 6 7 0 1 2]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. But it will return\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efalse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2 5 6 8 0 1 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, because its original array, i.e., \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[0 1 3 2 5 6 8]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, was not sorted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42893,"title":"Look Up Mapping","description":"Let the input is \r\n\r\nA = {[] [] [] [1] []};\r\n\r\nB = {'A','B','C','D','E'};\r\n\r\nMapped Output = 'D';","description_html":"\u003cp\u003eLet the input is\u003c/p\u003e\u003cp\u003eA = {[] [] [] [1] []};\u003c/p\u003e\u003cp\u003eB = {'A','B','C','D','E'};\u003c/p\u003e\u003cp\u003eMapped Output = 'D';\u003c/p\u003e","function_template":"function y = Mapp_It(A,B)\r\n  y = [];\r\nend","test_suite":"%%\r\nA = {[] [] [] [1] []};\r\nB = {'A','B','C','D','E'};\r\ny_correct = 'D';\r\nassert(isequal(Mapp_It(A,B),y_correct))\r\n\r\n\r\n%%\r\nA = {[] [] [] [1]; [] [1] [] []};\r\nB = {'A','B','C','D'};\r\ny_correct = {'D';'B'};\r\nassert(isequal(Mapp_It(A,B),y_correct))\r\n\r\n%%\r\nA = {[] [] [1]; [] [1] [];  [1] [] []};\r\nB = {'A','B','C'};\r\ny_correct = {'C';'B';'A'};\r\nassert(isequal(Mapp_It(A,B),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":25856,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-06-17T10:11:17.000Z","updated_at":"2025-12-23T02:55:41.000Z","published_at":"2016-06-17T10:11:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet the input is\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA = {[] [] [] [1] []};\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eB = {'A','B','C','D','E'};\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMapped Output = 'D';\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":42809,"title":"Sorting integers by their digits (Level 1)","description":"Given a vector, v, of positive integers, return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nExample:\r\n\r\nv = [14 3 268 14 210 1 80];\r\n\r\nw = [1 14 14 210 268 3 80];\r\n\r\nAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.","description_html":"\u003cp\u003eGiven a vector, v, of positive integers, return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14 3 268 14 210 1 80];\u003c/p\u003e\u003cp\u003ew = [1 14 14 210 268 3 80];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14 3 268 14 210 1 80];\r\nw_correct = [1 14 14 210 268 3 80];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [246 24680 2468 246 24 2 24680 24 2468 2];\r\nw_correct = [2 2 24 24 246 246 2468 2468 24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-19T20:04:25.000Z","updated_at":"2026-03-16T16:49:45.000Z","published_at":"2016-04-19T20:04:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of positive integers, return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14 3 268 14 210 1 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [1 14 14 210 268 3 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\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":42815,"title":"Sorting integers by their digits (Level 3)","description":"This is the next step up from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42811-sorting-integers-by-their-digits-level-2 Problem 42811\u003e.\r\n\r\nGiven a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nExample:\r\n\r\nv = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\r\n\r\nw = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\r\n\r\nAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\r\n\r\nNegative numbers take precedence over positive numbers.","description_html":"\u003cp\u003eThis is the next step up from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42811-sorting-integers-by-their-digits-level-2\"\u003eProblem 42811\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\u003c/p\u003e\u003cp\u003ew = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/p\u003e\u003cp\u003eNegative numbers take precedence over positive numbers.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\r\nw_correct = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-246 -24680 2468 246 24 -2 24680 -24 -2468 2];\r\nw_correct = [-2 2 -24 24 -246 246 -2468 2468 -24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-0.22222 0.22 0.222 0.2 0.2222];\r\nw_correct = [0.2 0.22 0.222 0.2222 -0.22222];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-20T19:57:51.000Z","updated_at":"2026-03-12T02:58:05.000Z","published_at":"2016-04-20T19:57:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the next step up from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42811-sorting-integers-by-their-digits-level-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42811\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14.38 80.42 3.14 268 -14.38 210 1 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [1 -14.38 14.38 210 268 3.14 80.42 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNegative numbers take precedence over positive numbers.\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":42894,"title":"Find longest run","description":"Write a function longest_run that takes as input an array of 0's and 1's and outputs the length and index of the longest consecutive run of either 0's or 1's. If there are multiple runs of the same length, it should output the first occurence.\r\n\r\nExamples:\r\n\r\n1. |longest_run([1 1 0 1])| should output |[2 1]|,\r\nsince the longest consecutive run is 11, which starts at index 1\r\n\r\n2. |longest_run([1 1 0 1 0 0 0 0 1 1 1])| should ouptut |[4 5]|,\r\nsince the longest consecutive run is 0000, which starts at index 5\r\n\r\n3. |longest_run([1 0])| should ouptut |[1 1]|,\r\nsince the _first_ longest consecutive run is 1, which starts at index 1","description_html":"\u003cp\u003eWrite a function longest_run that takes as input an array of 0's and 1's and outputs the length and index of the longest consecutive run of either 0's or 1's. If there are multiple runs of the same length, it should output the first occurence.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cp\u003e1. \u003ctt\u003elongest_run([1 1 0 1])\u003c/tt\u003e should output \u003ctt\u003e[2 1]\u003c/tt\u003e,\r\nsince the longest consecutive run is 11, which starts at index 1\u003c/p\u003e\u003cp\u003e2. \u003ctt\u003elongest_run([1 1 0 1 0 0 0 0 1 1 1])\u003c/tt\u003e should ouptut \u003ctt\u003e[4 5]\u003c/tt\u003e,\r\nsince the longest consecutive run is 0000, which starts at index 5\u003c/p\u003e\u003cp\u003e3. \u003ctt\u003elongest_run([1 0])\u003c/tt\u003e should ouptut \u003ctt\u003e[1 1]\u003c/tt\u003e,\r\nsince the \u003ci\u003efirst\u003c/i\u003e longest consecutive run is 1, which starts at index 1\u003c/p\u003e","function_template":"function [run_length, start_index] = longest_run(binary_array)\r\n%longest_run Finds longest consecutive runs of zeros or ones\r\n%   run_length is the length of the longest run of zeros or ones\r\n%   start_index is the index where the run begins\r\n\r\n    run_length = 1;\r\n    start_index = 1;\r\nend","test_suite":"%%\r\nbinary_array = [1 1 0 1];\r\nexpected_length = 2;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1 1 0 1 0 0 0 0 1 1 1];\r\nexpected_length = 4;\r\nexpected_index = 5;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1 0];\r\nexpected_length = 1;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1];\r\nexpected_length = 1;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));\r\n%%\r\nbinary_array = [1 1 1 1 1 1];\r\nexpected_length = 6;\r\nexpected_index = 1;\r\n[actual_length actual_index] = longest_run(binary_array);\r\nassert(isequal(expected_length, actual_length));\r\nassert(isequal(expected_index, actual_index));","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":26948,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":88,"test_suite_updated_at":"2016-06-29T20:27:09.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-06-29T18:38:46.000Z","updated_at":"2026-01-12T14:18:11.000Z","published_at":"2016-06-29T20:27: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\u003eWrite a function longest_run that takes as input an array of 0's and 1's and outputs the length and index of the longest consecutive run of either 0's or 1's. If there are multiple runs of the same length, it should output the first occurence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elongest_run([1 1 0 1])\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should output\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[2 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, since the longest consecutive run is 11, which starts at index 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\u003e2.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elongest_run([1 1 0 1 0 0 0 0 1 1 1])\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should ouptut\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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[4 5]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, since the longest consecutive run is 0000, which starts at index 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elongest_run([1 0])\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should ouptut\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[1 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, since 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003efirst\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e longest consecutive run is 1, which starts at index 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42811,"title":"Sorting integers by their digits (Level 2)","description":"This is the next step up from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42809-sorting-integers-by-their-digits Problem 42809\u003e.\r\n\r\nGiven a vector, v, of integers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nExample:\r\n\r\nv = [14 3 268 -14 210 1 80];\r\n\r\nw = [1 -14 14 210 268 3 80];\r\n\r\nAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\r\n\r\nNegative integers take precedence over positive integers.","description_html":"\u003cp\u003eThis is the next step up from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42809-sorting-integers-by-their-digits\"\u003eProblem 42809\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a vector, v, of integers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14 3 268 -14 210 1 80];\u003c/p\u003e\u003cp\u003ew = [1 -14 14 210 268 3 80];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\u003c/p\u003e\u003cp\u003eNegative integers take precedence over positive integers.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14 3 268 -14 210 1 80];\r\nw_correct = [1 -14 14 210 268 3 80];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-246 -24680 2468 246 24 -2 24680 -24 -2468 2];\r\nw_correct = [-2 2 -24 24 -246 246 -2468 2468 -24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-20T04:50:21.000Z","updated_at":"2026-03-12T02:54:13.000Z","published_at":"2016-04-20T04:50:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the next step up from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42809-sorting-integers-by-their-digits\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42809\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of integers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14 3 268 -14 210 1 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [1 -14 14 210 268 3 80];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple integers starting with the same digits, such as 1 and 14, shorter integers take precedence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNegative integers take precedence over positive integers.\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":340,"title":"Find last non-zero in a given dimension","description":"You are given a logical matrix *BW* _of any dimension_, and a dimension *dim*. You need to find the locations of the last non-zero element of *BW* in that given dimension. If no non-zeros exist at an element location, return a *0* at that location.\r\n\r\nFor example, given:\r\n\r\n  BW = [0 0 0 0; 1 1 1 1; 0 1 1 0]\r\n\r\nWhen dim = 1, you should return:\r\n\r\nans = [2 3 3 2], because these are the row numbers of the last non-zeroes in each column.\r\n\r\nWhen dim = 2, you should return:\r\n\r\nans = [0; 4; 3], because these are the column numbers of the last non-zeroes in each row.\r\n\r\nDon't forget that the input isn't restricted to 2D matrices.","description_html":"\u003cp\u003eYou are given a logical matrix \u003cb\u003eBW\u003c/b\u003e \u003ci\u003eof any dimension\u003c/i\u003e, and a dimension \u003cb\u003edim\u003c/b\u003e. You need to find the locations of the last non-zero element of \u003cb\u003eBW\u003c/b\u003e in that given dimension. If no non-zeros exist at an element location, return a \u003cb\u003e0\u003c/b\u003e at that location.\u003c/p\u003e\u003cp\u003eFor example, given:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eBW = [0 0 0 0; 1 1 1 1; 0 1 1 0]\r\n\u003c/pre\u003e\u003cp\u003eWhen dim = 1, you should return:\u003c/p\u003e\u003cp\u003eans = [2 3 3 2], because these are the row numbers of the last non-zeroes in each column.\u003c/p\u003e\u003cp\u003eWhen dim = 2, you should return:\u003c/p\u003e\u003cp\u003eans = [0; 4; 3], because these are the column numbers of the last non-zeroes in each row.\u003c/p\u003e\u003cp\u003eDon't forget that the input isn't restricted to 2D matrices.\u003c/p\u003e","function_template":"function out = findlastindim(BW,dim)\r\n  out = BW;\r\nend","test_suite":"%% Test the examples\r\nBW = [0 0 0 0; 1 1 1 1; 0 1 1 0];\r\nout_correct = [2 3 3 2];\r\nassert(isequal(findlastindim(BW,1),out_correct))\r\nout_correct = [0; 4; 3];\r\nassert(isequal(findlastindim(BW,2),out_correct))\r\n\r\n%% Test some different matrices\r\nBW = eye(10);\r\nout_correct = 1:10;\r\nassert(isequal(findlastindim(BW,1),out_correct))\r\nassert(isequal(findlastindim(BW,2),out_correct'))\r\n\r\n%% Test some different dimensions (and prevent hard-coded solutions)\r\nBW = rand(10)\u003e0.5;\r\nassert(isequal(findlastindim(BW,3),BW))\r\nassert(isequal(findlastindim(BW,4),BW))\r\n\r\n%% Test something in the 3rd dimension that is small enough to visualise.\r\nBW = cat(3, eye(5), fliplr(eye(5)));\r\nout_correct = [1     0     0     0     2\r\n     0     1     0     2     0\r\n     0     0     2     0     0\r\n     0     2     0     1     0\r\n     2     0     0     0     1];\r\nassert(isequal(findlastindim(BW,3),out_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":1101,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":49,"test_suite_updated_at":"2012-02-19T01:16:55.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2012-02-19T00:58:31.000Z","updated_at":"2026-01-06T07:39:02.000Z","published_at":"2012-02-19T01:17: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:t\u003eYou are given a logical matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eBW\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eof any dimension\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and a dimension\u003c/w:t\u003e\u003c/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\u003edim\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. You need to find the locations of the last non-zero element of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eBW\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in that given dimension. If no non-zeros exist at an element location, return a\u003c/w:t\u003e\u003c/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\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e at that location.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, given:\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[BW = [0 0 0 0; 1 1 1 1; 0 1 1 0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhen dim = 1, you should return:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eans = [2 3 3 2], because these are the row numbers of the last non-zeroes in each 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:t\u003eWhen dim = 2, you should return:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eans = [0; 4; 3], because these are the column numbers of the last non-zeroes in each row.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDon't forget that the input isn't restricted to 2D matrices.\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":42875,"title":"Assignment Problem","description":"Given a matrix where row i corresponds to person i, and column j corresponds to task j and cell (i,j) corresponds to the time taken for person i to complete task j. Output an assignment array for the minimal time taken for all tasks.\r\n\r\nFor example, if presented with the following matrix:\r\n\r\n x = [1,3,4,7;  \r\n      2,3,1,3;\r\n      4,2,3,7;\r\n      6,4,2,2;]\r\n\r\nYour output array would be:\r\n\r\n a = [1,3,2,4].\r\n\r\nWhere person one is assigned to task one, person three is assigned to task two , person two is assigned to task three and person four is assigned to task four.\r\n\r\nThis gives us a total time of 1+1+2+2=6 which is minimal.","description_html":"\u003cp\u003eGiven a matrix where row i corresponds to person i, and column j corresponds to task j and cell (i,j) corresponds to the time taken for person i to complete task j. Output an assignment array for the minimal time taken for all tasks.\u003c/p\u003e\u003cp\u003eFor example, if presented with the following matrix:\u003c/p\u003e\u003cpre\u003e x = [1,3,4,7;  \r\n      2,3,1,3;\r\n      4,2,3,7;\r\n      6,4,2,2;]\u003c/pre\u003e\u003cp\u003eYour output array would be:\u003c/p\u003e\u003cpre\u003e a = [1,3,2,4].\u003c/pre\u003e\u003cp\u003eWhere person one is assigned to task one, person three is assigned to task two , person two is assigned to task three and person four is assigned to task four.\u003c/p\u003e\u003cp\u003eThis gives us a total time of 1+1+2+2=6 which is minimal.\u003c/p\u003e","function_template":"function y = Assignment(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [2,12,8,5; 4,4,5,12; 3,10,8,3; 12,0,1,2];\r\ny_correct1 = [1,2,4,3];\r\ny_correct2 = [1,4,2,3];\r\ntest1 = isequal(Assignment(x),y_correct1);\r\ntest2 = isequal(Assignment(x),y_correct2);\r\nassert(test1||test2)\r\n\r\n%%\r\nx = [7,5,3,2,6; 6,3,6,6,5; 3,3,9,4,7; 4,5,3,3,4; 2,3,4,3,5];\r\ny_correct = [5,3,4,1,2];\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\nx(x==0) = 3;\r\ny_correct = 1:4;\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = 5 * ones(5);\r\nx(1,4) = 1;\r\nx(2,2) = 1;\r\nx(3,5) = 1;\r\nx(4,1) = 1;\r\nx(5,3) = 1;\r\ny_correct = [4,2,5,1,3];\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = 1:4;\r\nx = [x; circshift(x,1); circshift(x,2); circshift(x,3)];\r\ny_correct = 1:4;\r\nassert(isequal(Assignment(x),y_correct))\r\n\r\n%%\r\nx = [7,5,4; 14,16,2; 7,1,9];\r\ny_correct = [1,3,2];\r\nassert(isequal(Assignment(x),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":6,"created_by":64486,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":"2018-07-30T13:18:15.000Z","rescore_all_solutions":false,"group_id":43,"created_at":"2016-06-02T23:08:15.000Z","updated_at":"2026-03-11T23:46:24.000Z","published_at":"2016-06-02T23:18:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix where row i corresponds to person i, and column j corresponds to task j and cell (i,j) corresponds to the time taken for person i to complete task j. Output an assignment array for the minimal time taken for all tasks.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if presented with the following matrix:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [1,3,4,7;  \\n      2,3,1,3;\\n      4,2,3,7;\\n      6,4,2,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\u003eYour output array would be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a = [1,3,2,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:t\u003eWhere person one is assigned to task one, person three is assigned to task two , person two is assigned to task three and person four is assigned to task four.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis gives us a total time of 1+1+2+2=6 which is minimal.\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":42816,"title":"Sorting integers by their digits (Level 4)","description":"This is the next step up from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42815-sorting-integers-by-their-digits-level-3 Problem 42815\u003e.\r\n\r\nGiven a vector, v, of complex numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\r\n\r\nOnce all real digits have been used for sorting, it should continue with the imaginary part, which are further down the order.\r\n\r\nExample:\r\n\r\nv = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\r\n\r\nw = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\r\n\r\nAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\r\n\r\nNegative numbers take precedence over positive numbers.\r\n\r\nImaginary numbers should be treated as if they had a leading zero, because they have a zero real part.","description_html":"\u003cp\u003eThis is the next step up from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42815-sorting-integers-by-their-digits-level-3\"\u003eProblem 42815\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a vector, v, of complex numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/p\u003e\u003cp\u003eOnce all real digits have been used for sorting, it should continue with the imaginary part, which are further down the order.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003ev = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\u003c/p\u003e\u003cp\u003ew = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\u003c/p\u003e\u003cp\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/p\u003e\u003cp\u003eNegative numbers take precedence over positive numbers.\u003c/p\u003e\u003cp\u003eImaginary numbers should be treated as if they had a leading zero, because they have a zero real part.\u003c/p\u003e","function_template":"function w = soort(v)\r\n  w = v;\r\nend","test_suite":"%%\r\nv = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\r\nw_correct = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-246 -24680 2468 246 24 -2 24680 -24 -2468 2];\r\nw_correct = [-2 2 -24 24 -246 246 -2468 2468 -24680 24680];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = ones(1,100)*randi(100);\r\nw_correct = v;\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-0.22222 0.22 0.222 0.2 0.2222];\r\nw_correct = [0.2 0.22 0.222 0.2222 -0.22222];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [-6.28 4-12i 4.01+12i 4-13i 4+13i 4+14.9i 0-75i 0+391i 4-148i];\r\nw_correct = [0+391i 0-75i 4-12i 4-13i 4+13i 4-148i 4+14.9i 4.01+12i -6.28];\r\nassert(isequal(soort(v),w_correct))\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(soort(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":3,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":43,"created_at":"2016-04-20T20:15:04.000Z","updated_at":"2026-03-12T21:55:39.000Z","published_at":"2016-04-20T20:15: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\u003eThis is the next step up from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42815-sorting-integers-by-their-digits-level-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42815\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, v, of complex numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnce all real digits have been used for sorting, it should continue with the imaginary part, which are further down the 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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ev = [14.38 210+69i 80.42 3.14 0-15i 268 -14.38 210+64i 0+15i 1 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ew = [0-15i 0+15i 1 -14.38 14.38 210+64i 210+69i 268 3.14 80.42 80.44];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNegative numbers take precedence over positive numbers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImaginary numbers should be treated as if they had a leading zero, because they have a zero real part.\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":"group:\"Indexing V\"","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":"group:\"Indexing V\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Indexing V\"","","\"","Indexing V","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac4451f8e0\u003e":["Indexing V"],"#\u003cMathWorks::Search::Field:0x00007fac4451f840\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac4451eee0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac4451fca0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac4451fc00\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac4451fac0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac4451fa20\u003e":"group:\"Indexing V\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac4451fa20\u003e":"group:\"Indexing V\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007fac4451f8e0\u003e":["Indexing V"]}},"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":"group:\"Indexing V\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Indexing V\"","","\"","Indexing V","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac4451f8e0\u003e":["Indexing V"],"#\u003cMathWorks::Search::Field:0x00007fac4451f840\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac4451eee0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac4451fca0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac4451fc00\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac4451fac0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac4451fa20\u003e":"group:\"Indexing V\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac4451fa20\u003e":"group:\"Indexing V\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007fac4451f8e0\u003e":["Indexing V"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":314,"difficulty_rating":"easy"},{"id":43675,"difficulty_rating":"easy-medium"},{"id":42922,"difficulty_rating":"easy-medium"},{"id":42845,"difficulty_rating":"easy-medium"},{"id":42992,"difficulty_rating":"easy-medium"},{"id":43072,"difficulty_rating":"easy-medium"},{"id":42893,"difficulty_rating":"easy-medium"},{"id":42809,"difficulty_rating":"easy-medium"},{"id":42815,"difficulty_rating":"easy-medium"},{"id":42894,"difficulty_rating":"medium"},{"id":42811,"difficulty_rating":"medium"},{"id":340,"difficulty_rating":"medium"},{"id":42875,"difficulty_rating":"medium"},{"id":42816,"difficulty_rating":"medium"}]}}