{"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":43639,"title":"Counting candies","description":"In a classroom of |'n'| children, every even numbered child gets one big candy and every odd numbered child gets two small candies. Count the total number of candies |'x'| that one should bring to the class.\r\n\r\nFor example, if there are |n = 10| children in the class, the first child gets two candies, second child gets one candy, third child gets two candies and so on. Total number of candies required is |x = 15|.","description_html":"\u003cp\u003eIn a classroom of \u003ctt\u003e'n'\u003c/tt\u003e children, every even numbered child gets one big candy and every odd numbered child gets two small candies. Count the total number of candies \u003ctt\u003e'x'\u003c/tt\u003e that one should bring to the class.\u003c/p\u003e\u003cp\u003eFor example, if there are \u003ctt\u003en = 10\u003c/tt\u003e children in the class, the first child gets two candies, second child gets one candy, third child gets two candies and so on. Total number of candies required is \u003ctt\u003ex = 15\u003c/tt\u003e.\u003c/p\u003e","function_template":"function x = candyCount(n)\r\n  x = n;\r\nend","test_suite":"%%\r\nn = 13;\r\ny_correct = 20;\r\nassert(isequal(candyCount(n),y_correct))\r\n\r\n\r\n%%\r\nn = 24;\r\ny_correct = 36;\r\nassert(isequal(candyCount(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":70119,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-26T21:22:18.000Z","updated_at":"2026-03-04T16:13:53.000Z","published_at":"2016-10-26T21:22:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a classroom of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'n'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e children, every even numbered child gets one big candy and every odd numbered child gets two small candies. Count the total number of candies\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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'x'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that one should bring to the class.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 there are\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 10\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e children in the class, the first child gets two candies, second child gets one candy, third child gets two candies and so on. Total number of candies required is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex = 15\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":341,"title":"count to vector","description":"Return a matrix of numbers of dimension K by N, where K = prod(v), and N=length(v). The rows count from a vector of ones up to v, where the nth element of a row can take on the values 1:v(n).\r\n","description_html":"\u003cp\u003eReturn a matrix of numbers of dimension K by N, where K = prod(v), and N=length(v). The rows count from a vector of ones up to v, where the nth element of a row can take on the values 1:v(n).\u003c/p\u003e","function_template":"function y = count_to_v(v)\r\n  y = x;\r\nend","test_suite":"%%\r\nv = [1 2];\r\ny_correct = [1 1; 1 2];\r\nassert(isequal(count_to_v(v),y_correct))\r\n%%\r\nv = [3 2];\r\ny_correct = [1 1; 1 2;      2     1;      2     2; 3     1;  3     2];\r\nassert(isequal(count_to_v(v),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":153,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":92,"test_suite_updated_at":"2012-02-19T04:04:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-19T04:02:49.000Z","updated_at":"2026-03-11T12:09:55.000Z","published_at":"2012-02-19T04:10:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn a matrix of numbers of dimension K by N, where K = prod(v), and N=length(v). The rows count from a vector of ones up to v, where the nth element of a row can take on the values 1:v(n).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1290,"title":"A different counting method","description":"Given an array (x) of integers, the \"counting\" array (y) is showing the number of identical consecutive integers in x in front of the integer itself. For example, if\r\n\r\n* x = 1\r\n* y = [1 1],\r\n\r\nbecause there is one \"1\". If then\r\n\r\n* x = [1 1]\r\n* y = [2 1],\r\n\r\nbecause there are now two \"1\"s. Finally, a more complex example:\r\n\r\n* x = [1 2 2 4 4 3 0 0 1]\r\n* y = [1 1 2 2 2 4 1 3 2 0 1 1].\r\n\r\nSo y gets two elements for each series of identical integers in x. (I hope this problem does not exist already)","description_html":"\u003cp\u003eGiven an array (x) of integers, the \"counting\" array (y) is showing the number of identical consecutive integers in x in front of the integer itself. For example, if\u003c/p\u003e\u003cul\u003e\u003cli\u003ex = 1\u003c/li\u003e\u003cli\u003ey = [1 1],\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ebecause there is one \"1\". If then\u003c/p\u003e\u003cul\u003e\u003cli\u003ex = [1 1]\u003c/li\u003e\u003cli\u003ey = [2 1],\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ebecause there are now two \"1\"s. Finally, a more complex example:\u003c/p\u003e\u003cul\u003e\u003cli\u003ex = [1 2 2 4 4 3 0 0 1]\u003c/li\u003e\u003cli\u003ey = [1 1 2 2 2 4 1 3 2 0 1 1].\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSo y gets two elements for each series of identical integers in x. (I hope this problem does not exist already)\u003c/p\u003e","function_template":"function y = next_series(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = [1 0];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4];\r\ny_correct = [1 1 1 2 1 3 1 4];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0 0 0 0 0 0 0];\r\ny_correct = [9 0];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [2 2 2 0];\r\ny_correct = [3 2 1 0];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [0 0 3];\r\ny_correct = [2 0 1 3];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [1 1 1 1 2 2 4 4 4 4 4 3 0 0 1];\r\ny_correct = [4 1 2 2 5 4 1 3 2 0 1 1];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":8213,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-22T09:39:25.000Z","updated_at":"2026-04-02T10:50:06.000Z","published_at":"2013-02-22T10:06:27.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an array (x) of integers, the \\\"counting\\\" array (y) is showing the number of identical consecutive integers in x in front of the integer itself. For example, if\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\u003ex = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey = [1 1],\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause there is one \\\"1\\\". If then\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\u003ex = [1 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey = [2 1],\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause there are now two \\\"1\\\"s. Finally, a more complex example:\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\u003ex = [1 2 2 4 4 3 0 0 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey = [1 1 2 2 2 4 1 3 2 0 1 1].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo y gets two elements for each series of identical integers in x. (I hope this problem does not exist already)\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":107,"title":"Count from 0 to N^M in base N.","description":"Return an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number.  Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.\r\n\r\nExample 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)\r\n\r\nans =\r\n\r\n     0     0     1     1\r\n     0     1     0     1\r\n\r\n\r\n\r\nExample 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 3)\r\n\r\nans =\r\n\r\n     0     0     0     1     1     1     2     2     2\r\n     0     1     2     0     1     2     0     1     2\r\n","description_html":"\u003cp\u003eReturn an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number.  Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.\u003c/p\u003e\u003cp\u003eExample 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)\u003c/p\u003e\u003cp\u003eans =\u003c/p\u003e\u003cpre\u003e     0     0     1     1\r\n     0     1     0     1\u003c/pre\u003e\u003cp\u003eExample 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 3)\u003c/p\u003e\u003cp\u003eans =\u003c/p\u003e\u003cpre\u003e     0     0     0     1     1     1     2     2     2\r\n     0     1     2     0     1     2     0     1     2\u003c/pre\u003e","function_template":"function y = countInBaseN(M,N)\r\n  y = M;\r\nend","test_suite":"%%\r\nM = 2;\r\nN = 2;\r\ny_correct = [0     0     1     1; 0     1     0     1];\r\nassert(isequal(countInBaseN(M,N),y_correct))\r\n%%\r\nM = 2;\r\nN = 3;\r\ny_correct = [ 0 0 0 1 1 1 2 2 2;  0 1 2 0 1 2 0 1 2];\r\nassert(isequal(countInBaseN(M,N),y_correct))\r\n%%\r\nM = 3;\r\nN = 4;\r\ny_correct = [   0     0     0\r\n     0     0     1\r\n     0     0     2\r\n     0     0     3\r\n     0     1     0\r\n     0     1     1\r\n     0     1     2\r\n     0     1     3\r\n     0     2     0\r\n     0     2     1\r\n     0     2     2\r\n     0     2     3\r\n     0     3     0\r\n     0     3     1\r\n     0     3     2\r\n     0     3     3\r\n     1     0     0\r\n     1     0     1\r\n     1     0     2\r\n     1     0     3\r\n     1     1     0\r\n     1     1     1\r\n     1     1     2\r\n     1     1     3\r\n     1     2     0\r\n     1     2     1\r\n     1     2     2\r\n     1     2     3\r\n     1     3     0\r\n     1     3     1\r\n     1     3     2\r\n     1     3     3\r\n     2     0     0\r\n     2     0     1\r\n     2     0     2\r\n     2     0     3\r\n     2     1     0\r\n     2     1     1\r\n     2     1     2\r\n     2     1     3\r\n     2     2     0\r\n     2     2     1\r\n     2     2     2\r\n     2     2     3\r\n     2     3     0\r\n     2     3     1\r\n     2     3     2\r\n     2     3     3\r\n     3     0     0\r\n     3     0     1\r\n     3     0     2\r\n     3     0     3\r\n     3     1     0\r\n     3     1     1\r\n     3     1     2\r\n     3     1     3\r\n     3     2     0\r\n     3     2     1\r\n     3     2     2\r\n     3     2     3\r\n     3     3     0\r\n     3     3     1\r\n     3     3     2\r\n     3     3     3];\r\nassert(isequal(countInBaseN(M,N),y_correct'))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":153,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":240,"test_suite_updated_at":"2012-01-26T03:35:34.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T03:35:34.000Z","updated_at":"2026-02-04T21:25:48.000Z","published_at":"2012-01-26T23:26:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number. Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eans =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     0     0     1     1\\n     0     1     0     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 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\u003eans =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     0     0     0     1     1     1     2     2     2\\n     0     1     2     0     1     2     0     1     2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42788,"title":"Rearrange string","description":"Input is a given string. Output is the number of ways to rearrange the string.","description_html":"\u003cp\u003eInput is a given string. Output is the number of ways to rearrange the string.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 'RAMANUJAN';\r\ny_correct = 30239;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 'PRITOM';\r\ny_correct = 719;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 'ABUL';\r\ny_correct = 23;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 'EULER';\r\ny_correct = 59;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":65236,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2019-10-23T23:47:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-27T17:04:44.000Z","updated_at":"2025-11-17T15:12:20.000Z","published_at":"2016-03-27T17:04:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput is a given string. Output is the number of ways to rearrange the string.\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":367,"title":"Specific Element Count","description":"Given a vector _v_ and a element _e_, return the number of occurrences of _e_ in _v_.\r\n\r\nNote: NaNs are equal and there may be no occurrences of _e_ in _v_\r\n\r\nExample:\r\n\r\n  v = 1:10\r\n  e = 2\r\n  output = 1","description_html":"\u003cp\u003eGiven a vector \u003ci\u003ev\u003c/i\u003e and a element \u003ci\u003ee\u003c/i\u003e, return the number of occurrences of \u003ci\u003ee\u003c/i\u003e in \u003ci\u003ev\u003c/i\u003e.\u003c/p\u003e\u003cp\u003eNote: NaNs are equal and there may be no occurrences of \u003ci\u003ee\u003c/i\u003e in \u003ci\u003ev\u003c/i\u003e\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = 1:10\r\ne = 2\r\noutput = 1\r\n\u003c/pre\u003e","function_template":"function ct = ecount(v,e)\r\n  ct = 0;\r\nend","test_suite":"%%\r\nassert(isequal(ecount(1:10,2),1))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 1 1 1 1],1),8))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 1 1 1 1],2),0))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 NaN NaN 1 1],NaN),2))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 NaN NaN 1 1],17),0))\r\n\r\n%%\r\nassert(isequal(ecount([15 13 6 2 71 -5 -7 15],15),2))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":939,"test_suite_updated_at":"2017-10-10T16:50:31.000Z","rescore_all_solutions":true,"group_id":12,"created_at":"2012-02-20T19:38:37.000Z","updated_at":"2026-03-30T13:25:15.000Z","published_at":"2012-02-20T19:38: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\u003eGiven a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a element\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return the number of occurrences of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: NaNs are equal and there may be no occurrences of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[v = 1:10\\ne = 2\\noutput = 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":51246,"title":"Characterize the final state of another digit inventory sequence","description":null,"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: 370.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 185.217px; transform-origin: 407px 185.217px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.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: 49.7917px 7.91667px; transform-origin: 49.7917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCody Problems \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e46122\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 15.5583px 7.91667px; transform-origin: 15.5583px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46571\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e46571\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 264.525px 7.91667px; transform-origin: 264.525px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved a digit inventory sequence in which one term in the sequence describes the previous. For example, if one term is 411, the next would be 2114: two 1’s, one 4. For some starting numbers, the sequence reaches a steady state, but for others, the terms oscillate.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 210.283px 7.91667px; transform-origin: 210.283px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA different form of a digit inventory is formed by listing the counts of \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.00833px 7.91667px; transform-origin: 7.00833px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eall\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 158.325px 7.91667px; transform-origin: 158.325px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e digits—in the order 1-9 and 0—and concatenating them for the next term in the sequence. If the initial seed is 570, then the next three terms would be \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 130.9px 7.91667px; transform-origin: 130.9px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e0000101001, 3000000007, 0010001008\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 361.7px 7.91667px; transform-origin: 361.7px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe first term arises because 570 has zero 1s, 2s, 3s, and 4s; one 5; zero 6s, one 7; zero 8s and 9s; and one 0. The second term arises because the first has three 1s, seven 0s, and zero of everything else. If we continue to generate terms, we will find that the seventh and eighth terms will repeat. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.933px 7.91667px; transform-origin: 381.933px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAt first, I thought that this sequence always reaches a state in which these same two terms oscillate, but I have since found a few seeds that lead to a steady state. \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.817px 7.91667px; transform-origin: 381.817px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes a seed as a string and determines the number of the term at which the final state begins and the period of the repeated terms. Take the initial seed to be term 1. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 371.042px 7.91667px; transform-origin: 371.042px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOptional: The function is not required to return the terms themselves, but the terms in the final state are interesting. The seeds in the test suite lead to only two sets of final terms. Can you find seeds that lead to different final terms? \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [n,period] = digitInventory2(y1)\r\n  n = f1(y1);\r\n  period = f2(y1);\r\nend","test_suite":"%%\r\ny1 = '1';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '53';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '100';\r\nn_correct = 6;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '570';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1000';\r\nn_correct = 6;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1002';\r\nn_correct = 5;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '10023';\r\nn_correct = 4;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '10234';\r\nn_correct = 8;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '11111';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '12345';\r\nn_correct = 8;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '11233344';\r\nn_correct = 4;\r\nperiod_correct = 1;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '112233344';\r\nn_correct = 4;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '11223334444';\r\nn_correct = 4;\r\nperiod_correct = 1;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '112233344445';\r\nn_correct = 6;\r\nperiod_correct = 1;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1111111111';\r\nn_correct = 8;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1234567890';\r\nn_correct = 9;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '122333444455555666666777777788888888999999999';\r\nn_correct = 10;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2021-03-27T22:51:08.000Z","updated_at":"2025-12-16T21:32:44.000Z","published_at":"2021-03-27T23:42:35.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\u003eCody Problems \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\\\"\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e46122\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46571\\\"\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e46571\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e involved a digit inventory sequence in which one term in the sequence describes the previous. For example, if one term is 411, the next would be 2114: two 1’s, one 4. For some starting numbers, the sequence reaches a steady state, but for others, the terms oscillate.\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 different form of a digit inventory is formed by listing the counts of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e digits—in the order 1-9 and 0—and concatenating them for the next term in the sequence. If the initial seed is 570, then the next three terms 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[0000101001, 3000000007, 0010001008]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first term arises because 570 has zero 1s, 2s, 3s, and 4s; one 5; zero 6s, one 7; zero 8s and 9s; and one 0. The second term arises because the first has three 1s, seven 0s, and zero of everything else. If we continue to generate terms, we will find that the seventh and eighth terms will repeat. \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\u003eAt first, I thought that this sequence always reaches a state in which these same two terms oscillate, but I have since found a few seeds that lead to a steady state. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes a seed as a string and determines the number of the term at which the final state begins and the period of the repeated terms. Take the initial seed to be term 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\u003eOptional: The function is not required to return the terms themselves, but the terms in the final state are interesting. The seeds in the test suite lead to only two sets of final terms. Can you find seeds that lead to different final terms? \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":46571,"title":"Characterize the final state of the digit inventory sequence","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 317.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 158.65px; transform-origin: 407px 158.65px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCody Problem 46122\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 313.533px 7.91667px; transform-origin: 313.533px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved a counting sequence that I called the digit inventory sequence, in which each term provides an inventory of the digits of the previous term. If the initial number of the sequence is 24, then the sequence is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 304.15px 7.91667px; transform-origin: 304.15px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 265.65px 7.91667px; transform-origin: 265.65px 7.91667px; \"\u003e   24, 1214, 211214, 312214, 21221314, 31321314, 31123314, 31123314, \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 11.55px 7.91667px; text-decoration: none; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 11.55px 7.91667px; \"\u003e...\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(2, 128, 9); border-block-start-color: rgb(2, 128, 9); border-bottom-color: rgb(2, 128, 9); border-inline-end-color: rgb(2, 128, 9); border-inline-start-color: rgb(2, 128, 9); border-left-color: rgb(2, 128, 9); border-right-color: rgb(2, 128, 9); border-top-color: rgb(2, 128, 9); caret-color: rgb(2, 128, 9); color: rgb(2, 128, 9); column-rule-color: rgb(2, 128, 9); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(2, 128, 9); perspective-origin: 26.95px 7.91667px; text-decoration: none; text-decoration-color: rgb(2, 128, 9); text-emphasis-color: rgb(2, 128, 9); transform-origin: 26.95px 7.91667px; \"\u003e       \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 7.91667px; transform-origin: 384px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the third term provides an inventory of the second: two 1's, one 2, one 4. Notice that starting with 24 leads to a steady state after 7 terms because all subsequent terms are equal to the seventh (i.e., 31123314). \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 136.133px 7.91667px; transform-origin: 136.133px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHowever, the final state is not necessarily a \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 20.6167px 7.91667px; transform-origin: 20.6167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003esteady\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 178.125px 7.91667px; transform-origin: 178.125px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e state. If the starting number is 210, then the sequence is \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 20.4333px; transform-origin: 404px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 331.1px 7.91667px; transform-origin: 331.1px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   210, 101112, 104112, 10311214, 1041121314, 1051121324, 104122131415, 105122132415, \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 292.6px 7.91667px; transform-origin: 292.6px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 281.05px 7.91667px; transform-origin: 281.05px 7.91667px; \"\u003e   104132131425, 104122232415, 103142132415, 104122232415, 103142132415, \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 11.55px 7.91667px; text-decoration: none; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 11.55px 7.91667px; \"\u003e...\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 7.91667px; transform-origin: 384px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe tenth and eleventh terms repeat indefinitely. In other words, the repeated terms start at term 10, and they have a period of 2. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 372.875px 7.91667px; transform-origin: 372.875px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine the number of the term at which the final state begins and the period of the repeated terms.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 7.91667px; transform-origin: 0px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [n,period] = digInvFinalState(y1)\r\n  n = f1(y1);\r\n  period = f2(y1);\r\nend","test_suite":"%%\r\ny1 = 24;\r\nn_correct = 7;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 210;\r\nn_correct = 10;\r\nperiod_correct = 2;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 1;\r\nn_correct = 13;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 10;\r\nn_correct = 10;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 22;\r\nn_correct = 1;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 40;\r\nn_correct = 10;\r\nperiod_correct = 2;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 50;\r\nn_correct = 11;\r\nperiod_correct = 3;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\nfor y1 = 567:571\r\n    [n(y1-566),period(y1-566)] = digInvFinalState(y1);\r\nend\r\nprod_correct = 136;\r\nassert(isequal(n*period',prod_correct));","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-08-29T02:58:19.000Z","updated_at":"2025-12-16T21:25:08.000Z","published_at":"2020-08-29T04:10: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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Problem 46122\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involved a counting sequence that I called the digit inventory sequence, in which each term provides an inventory of the digits of the previous term. If the initial number of the sequence is 24, then the sequence is\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   24, 1214, 211214, 312214, 21221314, 31321314, 31123314, 31123314, ...       ]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, the third term provides an inventory of the second: two 1's, one 2, one 4. Notice that starting with 24 leads to a steady state after 7 terms because all subsequent terms are equal to the seventh (i.e., 31123314). \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\u003eHowever, the final state is not necessarily a \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esteady\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e state. If the starting number is 210, then the sequence is \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   210, 101112, 104112, 10311214, 1041121314, 1051121324, 104122131415, 105122132415, \\n   104132131425, 104122232415, 103142132415, 104122232415, 103142132415, ...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe tenth and eleventh terms repeat indefinitely. In other words, the repeated terms start at term 10, and they have a period of 2. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine the number of the term at which the final state begins and the period of the repeated terms.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":45578,"title":"Create a matrix that counts up diagonally","description":"Given a single input _N_, create a _N_ x _N_ matrix that counts from 1 : _N_ ², (along up-right diagonals, starting with 1 in the top left corner. For example, given N=4...\r\n\r\n  1  3  6 10\r\n  2  5  9 13 \r\n  4  8 12 15 \r\n  7 11 14 16\r\n  \r\n\r\nNotice as you move up a row and right a column (↗) the values always increase by one. The value '1' should always go in the top left corner, with '2' directly below it. From there fill in the upward-rightward diagonals with the next higher integer until the matrix is complete. Assume N will always be a positive integer greater than 1 (N \u003e= 2).\r\n","description_html":"\u003cp\u003eGiven a single input \u003ci\u003eN\u003c/i\u003e, create a \u003ci\u003eN\u003c/i\u003e x \u003ci\u003eN\u003c/i\u003e matrix that counts from 1 : \u003ci\u003eN\u003c/i\u003e ², (along up-right diagonals, starting with 1 in the top left corner. For example, given N=4...\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1  3  6 10\r\n2  5  9 13 \r\n4  8 12 15 \r\n7 11 14 16\r\n\u003c/pre\u003e\u003cp\u003eNotice as you move up a row and right a column (↗) the values always increase by one. The value '1' should always go in the top left corner, with '2' directly below it. From there fill in the upward-rightward diagonals with the next higher integer until the matrix is complete. Assume N will always be a positive integer greater than 1 (N \u0026gt;= 2).\u003c/p\u003e","function_template":"function mx = not_hankel(N)\r\n\r\n    mx = ones(N); %replace with your code\r\n\r\nend","test_suite":"%%\r\nN = 20;\r\n\r\nmx_correct = [...\r\n     1     3     6    10    15    21    28    36    45    55    66    78    91   105   120   136   153   171   190   210\r\n     2     5     9    14    20    27    35    44    54    65    77    90   104   119   135   152   170   189   209   229\r\n     4     8    13    19    26    34    43    53    64    76    89   103   118   134   151   169   188   208   228   247\r\n     7    12    18    25    33    42    52    63    75    88   102   117   133   150   168   187   207   227   246   264\r\n    11    17    24    32    41    51    62    74    87   101   116   132   149   167   186   206   226   245   263   280\r\n    16    23    31    40    50    61    73    86   100   115   131   148   166   185   205   225   244   262   279   295\r\n    22    30    39    49    60    72    85    99   114   130   147   165   184   204   224   243   261   278   294   309\r\n    29    38    48    59    71    84    98   113   129   146   164   183   203   223   242   260   277   293   308   322\r\n    37    47    58    70    83    97   112   128   145   163   182   202   222   241   259   276   292   307   321   334\r\n    46    57    69    82    96   111   127   144   162   181   201   221   240   258   275   291   306   320   333   345\r\n    56    68    81    95   110   126   143   161   180   200   220   239   257   274   290   305   319   332   344   355\r\n    67    80    94   109   125   142   160   179   199   219   238   256   273   289   304   318   331   343   354   364\r\n    79    93   108   124   141   159   178   198   218   237   255   272   288   303   317   330   342   353   363   372\r\n    92   107   123   140   158   177   197   217   236   254   271   287   302   316   329   341   352   362   371   379\r\n   106   122   139   157   176   196   216   235   253   270   286   301   315   328   340   351   361   370   378   385\r\n   121   138   156   175   195   215   234   252   269   285   300   314   327   339   350   360   369   377   384   390\r\n   137   155   174   194   214   233   251   268   284   299   313   326   338   349   359   368   376   383   389   394\r\n   154   173   193   213   232   250   267   283   298   312   325   337   348   358   367   375   382   388   393   397\r\n   172   192   212   231   249   266   282   297   311   324   336   347   357   366   374   381   387   392   396   399\r\n   191   211   230   248   265   281   296   310   323   335   346   356   365   373   380   386   391   395   398   400\r\n   ];\r\n\r\nassert(isequal(not_hankel(N),mx_correct))\r\n\r\n\r\n\r\n%%\r\nN = 3;\r\n\r\nmx_correct = [...\r\n     1     3     6\r\n     2     5     8\r\n     4     7     9\r\n     ];\r\n\r\nassert(isequal(not_hankel(N),mx_correct))\r\n\r\n\r\n\r\n%%\r\nrng('shuffle')\r\nN  = randi(99)+5;\r\nr = repmat((0:(N-1))',1,N) + (0:(N-1));\r\np = ((.5.*r.^2 + .5.*r) + (r(1,:)+1));\r\nq = rot90(hankel(fliplr(0:N-1)),2).^2;\r\nmx_correct = p - q;\r\nassert(isequal(not_hankel(N),mx_correct))\r\n\r\n\r\n\r\n%% \r\nN = 2;\r\nmx_correct =...\r\n[...\r\n    1  3\r\n    2  4 \r\n];\r\n\r\nassert(isequal(not_hankel(N),mx_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":18354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":22,"test_suite_updated_at":"2020-05-22T17:05:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-22T16:46:56.000Z","updated_at":"2026-01-20T13:24:26.000Z","published_at":"2020-05-22T16:46: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 single input\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, create 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e x\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix that counts from 1 :\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ², (along up-right diagonals, starting with 1 in the top left corner. For example, given N=4...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1  3  6 10\\n2  5  9 13 \\n4  8 12 15 \\n7 11 14 16]]\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\u003eNotice as you move up a row and right a column (↗) the values always increase by one. The value '1' should always go in the top left corner, with '2' directly below it. From there fill in the upward-rightward diagonals with the next higher integer until the matrix is complete. Assume N will always be a positive integer greater than 1 (N \u0026gt;= 2).\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":42787,"title":"How many ways to write ","description":"How many ways to write a positive integer x as the sum of n numbers , where , x\u003en and no n number is less than -2.","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: 361px 8px; transform-origin: 361px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHow many ways to write a positive integer x as the sum of n numbers , where , x\u0026gt;n and no n number is less than -2.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x,n)\r\n  y = x+n;\r\nend","test_suite":"%%\r\nx=1;\r\nn=2;\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=7;\r\nn=3;\r\ny_correct = 66;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=40;\r\nn=7;\r\ny_correct =277962685 ;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=40;\r\nn=4;\r\ny_correct =79079;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":20,"created_by":65236,"edited_by":223089,"edited_at":"2023-02-07T10:08:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2023-02-07T10:08:32.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-27T16:59:02.000Z","updated_at":"2025-12-16T04:49:04.000Z","published_at":"2016-03-27T16:59:02.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHow many ways to write a positive integer x as the sum of n numbers , where , x\u0026gt;n and no n number is less than -2.\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":43639,"title":"Counting candies","description":"In a classroom of |'n'| children, every even numbered child gets one big candy and every odd numbered child gets two small candies. Count the total number of candies |'x'| that one should bring to the class.\r\n\r\nFor example, if there are |n = 10| children in the class, the first child gets two candies, second child gets one candy, third child gets two candies and so on. Total number of candies required is |x = 15|.","description_html":"\u003cp\u003eIn a classroom of \u003ctt\u003e'n'\u003c/tt\u003e children, every even numbered child gets one big candy and every odd numbered child gets two small candies. Count the total number of candies \u003ctt\u003e'x'\u003c/tt\u003e that one should bring to the class.\u003c/p\u003e\u003cp\u003eFor example, if there are \u003ctt\u003en = 10\u003c/tt\u003e children in the class, the first child gets two candies, second child gets one candy, third child gets two candies and so on. Total number of candies required is \u003ctt\u003ex = 15\u003c/tt\u003e.\u003c/p\u003e","function_template":"function x = candyCount(n)\r\n  x = n;\r\nend","test_suite":"%%\r\nn = 13;\r\ny_correct = 20;\r\nassert(isequal(candyCount(n),y_correct))\r\n\r\n\r\n%%\r\nn = 24;\r\ny_correct = 36;\r\nassert(isequal(candyCount(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":70119,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-26T21:22:18.000Z","updated_at":"2026-03-04T16:13:53.000Z","published_at":"2016-10-26T21:22:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a classroom of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'n'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e children, every even numbered child gets one big candy and every odd numbered child gets two small candies. Count the total number of candies\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w: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'x'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that one should bring to the class.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 there are\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 10\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e children in the class, the first child gets two candies, second child gets one candy, third child gets two candies and so on. Total number of candies required is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex = 15\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":341,"title":"count to vector","description":"Return a matrix of numbers of dimension K by N, where K = prod(v), and N=length(v). The rows count from a vector of ones up to v, where the nth element of a row can take on the values 1:v(n).\r\n","description_html":"\u003cp\u003eReturn a matrix of numbers of dimension K by N, where K = prod(v), and N=length(v). The rows count from a vector of ones up to v, where the nth element of a row can take on the values 1:v(n).\u003c/p\u003e","function_template":"function y = count_to_v(v)\r\n  y = x;\r\nend","test_suite":"%%\r\nv = [1 2];\r\ny_correct = [1 1; 1 2];\r\nassert(isequal(count_to_v(v),y_correct))\r\n%%\r\nv = [3 2];\r\ny_correct = [1 1; 1 2;      2     1;      2     2; 3     1;  3     2];\r\nassert(isequal(count_to_v(v),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":153,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":92,"test_suite_updated_at":"2012-02-19T04:04:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-19T04:02:49.000Z","updated_at":"2026-03-11T12:09:55.000Z","published_at":"2012-02-19T04:10:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn a matrix of numbers of dimension K by N, where K = prod(v), and N=length(v). The rows count from a vector of ones up to v, where the nth element of a row can take on the values 1:v(n).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1290,"title":"A different counting method","description":"Given an array (x) of integers, the \"counting\" array (y) is showing the number of identical consecutive integers in x in front of the integer itself. For example, if\r\n\r\n* x = 1\r\n* y = [1 1],\r\n\r\nbecause there is one \"1\". If then\r\n\r\n* x = [1 1]\r\n* y = [2 1],\r\n\r\nbecause there are now two \"1\"s. Finally, a more complex example:\r\n\r\n* x = [1 2 2 4 4 3 0 0 1]\r\n* y = [1 1 2 2 2 4 1 3 2 0 1 1].\r\n\r\nSo y gets two elements for each series of identical integers in x. (I hope this problem does not exist already)","description_html":"\u003cp\u003eGiven an array (x) of integers, the \"counting\" array (y) is showing the number of identical consecutive integers in x in front of the integer itself. For example, if\u003c/p\u003e\u003cul\u003e\u003cli\u003ex = 1\u003c/li\u003e\u003cli\u003ey = [1 1],\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ebecause there is one \"1\". If then\u003c/p\u003e\u003cul\u003e\u003cli\u003ex = [1 1]\u003c/li\u003e\u003cli\u003ey = [2 1],\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ebecause there are now two \"1\"s. Finally, a more complex example:\u003c/p\u003e\u003cul\u003e\u003cli\u003ex = [1 2 2 4 4 3 0 0 1]\u003c/li\u003e\u003cli\u003ey = [1 1 2 2 2 4 1 3 2 0 1 1].\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSo y gets two elements for each series of identical integers in x. (I hope this problem does not exist already)\u003c/p\u003e","function_template":"function y = next_series(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = [1 0];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4];\r\ny_correct = [1 1 1 2 1 3 1 4];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0 0 0 0 0 0 0];\r\ny_correct = [9 0];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [2 2 2 0];\r\ny_correct = [3 2 1 0];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [0 0 3];\r\ny_correct = [2 0 1 3];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n%%\r\nx = [1 1 1 1 2 2 4 4 4 4 4 3 0 0 1];\r\ny_correct = [4 1 2 2 5 4 1 3 2 0 1 1];\r\nassert(isequal(next_series(x),y_correct))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":8213,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-22T09:39:25.000Z","updated_at":"2026-04-02T10:50:06.000Z","published_at":"2013-02-22T10:06:27.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an array (x) of integers, the \\\"counting\\\" array (y) is showing the number of identical consecutive integers in x in front of the integer itself. For example, if\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\u003ex = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey = [1 1],\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause there is one \\\"1\\\". If then\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\u003ex = [1 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey = [2 1],\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause there are now two \\\"1\\\"s. Finally, a more complex example:\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\u003ex = [1 2 2 4 4 3 0 0 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey = [1 1 2 2 2 4 1 3 2 0 1 1].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo y gets two elements for each series of identical integers in x. (I hope this problem does not exist already)\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":107,"title":"Count from 0 to N^M in base N.","description":"Return an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number.  Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.\r\n\r\nExample 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)\r\n\r\nans =\r\n\r\n     0     0     1     1\r\n     0     1     0     1\r\n\r\n\r\n\r\nExample 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 3)\r\n\r\nans =\r\n\r\n     0     0     0     1     1     1     2     2     2\r\n     0     1     2     0     1     2     0     1     2\r\n","description_html":"\u003cp\u003eReturn an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number.  Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.\u003c/p\u003e\u003cp\u003eExample 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)\u003c/p\u003e\u003cp\u003eans =\u003c/p\u003e\u003cpre\u003e     0     0     1     1\r\n     0     1     0     1\u003c/pre\u003e\u003cp\u003eExample 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 3)\u003c/p\u003e\u003cp\u003eans =\u003c/p\u003e\u003cpre\u003e     0     0     0     1     1     1     2     2     2\r\n     0     1     2     0     1     2     0     1     2\u003c/pre\u003e","function_template":"function y = countInBaseN(M,N)\r\n  y = M;\r\nend","test_suite":"%%\r\nM = 2;\r\nN = 2;\r\ny_correct = [0     0     1     1; 0     1     0     1];\r\nassert(isequal(countInBaseN(M,N),y_correct))\r\n%%\r\nM = 2;\r\nN = 3;\r\ny_correct = [ 0 0 0 1 1 1 2 2 2;  0 1 2 0 1 2 0 1 2];\r\nassert(isequal(countInBaseN(M,N),y_correct))\r\n%%\r\nM = 3;\r\nN = 4;\r\ny_correct = [   0     0     0\r\n     0     0     1\r\n     0     0     2\r\n     0     0     3\r\n     0     1     0\r\n     0     1     1\r\n     0     1     2\r\n     0     1     3\r\n     0     2     0\r\n     0     2     1\r\n     0     2     2\r\n     0     2     3\r\n     0     3     0\r\n     0     3     1\r\n     0     3     2\r\n     0     3     3\r\n     1     0     0\r\n     1     0     1\r\n     1     0     2\r\n     1     0     3\r\n     1     1     0\r\n     1     1     1\r\n     1     1     2\r\n     1     1     3\r\n     1     2     0\r\n     1     2     1\r\n     1     2     2\r\n     1     2     3\r\n     1     3     0\r\n     1     3     1\r\n     1     3     2\r\n     1     3     3\r\n     2     0     0\r\n     2     0     1\r\n     2     0     2\r\n     2     0     3\r\n     2     1     0\r\n     2     1     1\r\n     2     1     2\r\n     2     1     3\r\n     2     2     0\r\n     2     2     1\r\n     2     2     2\r\n     2     2     3\r\n     2     3     0\r\n     2     3     1\r\n     2     3     2\r\n     2     3     3\r\n     3     0     0\r\n     3     0     1\r\n     3     0     2\r\n     3     0     3\r\n     3     1     0\r\n     3     1     1\r\n     3     1     2\r\n     3     1     3\r\n     3     2     0\r\n     3     2     1\r\n     3     2     2\r\n     3     2     3\r\n     3     3     0\r\n     3     3     1\r\n     3     3     2\r\n     3     3     3];\r\nassert(isequal(countInBaseN(M,N),y_correct'))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":153,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":240,"test_suite_updated_at":"2012-01-26T03:35:34.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T03:35:34.000Z","updated_at":"2026-02-04T21:25:48.000Z","published_at":"2012-01-26T23:26:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number. Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eans =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     0     0     1     1\\n     0     1     0     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 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\u003eans =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     0     0     0     1     1     1     2     2     2\\n     0     1     2     0     1     2     0     1     2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42788,"title":"Rearrange string","description":"Input is a given string. Output is the number of ways to rearrange the string.","description_html":"\u003cp\u003eInput is a given string. Output is the number of ways to rearrange the string.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 'RAMANUJAN';\r\ny_correct = 30239;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 'PRITOM';\r\ny_correct = 719;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 'ABUL';\r\ny_correct = 23;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 'EULER';\r\ny_correct = 59;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":65236,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2019-10-23T23:47:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-27T17:04:44.000Z","updated_at":"2025-11-17T15:12:20.000Z","published_at":"2016-03-27T17:04:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput is a given string. Output is the number of ways to rearrange the string.\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":367,"title":"Specific Element Count","description":"Given a vector _v_ and a element _e_, return the number of occurrences of _e_ in _v_.\r\n\r\nNote: NaNs are equal and there may be no occurrences of _e_ in _v_\r\n\r\nExample:\r\n\r\n  v = 1:10\r\n  e = 2\r\n  output = 1","description_html":"\u003cp\u003eGiven a vector \u003ci\u003ev\u003c/i\u003e and a element \u003ci\u003ee\u003c/i\u003e, return the number of occurrences of \u003ci\u003ee\u003c/i\u003e in \u003ci\u003ev\u003c/i\u003e.\u003c/p\u003e\u003cp\u003eNote: NaNs are equal and there may be no occurrences of \u003ci\u003ee\u003c/i\u003e in \u003ci\u003ev\u003c/i\u003e\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev = 1:10\r\ne = 2\r\noutput = 1\r\n\u003c/pre\u003e","function_template":"function ct = ecount(v,e)\r\n  ct = 0;\r\nend","test_suite":"%%\r\nassert(isequal(ecount(1:10,2),1))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 1 1 1 1],1),8))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 1 1 1 1],2),0))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 NaN NaN 1 1],NaN),2))\r\n\r\n%%\r\nassert(isequal(ecount([1 1 1 1 NaN NaN 1 1],17),0))\r\n\r\n%%\r\nassert(isequal(ecount([15 13 6 2 71 -5 -7 15],15),2))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":939,"test_suite_updated_at":"2017-10-10T16:50:31.000Z","rescore_all_solutions":true,"group_id":12,"created_at":"2012-02-20T19:38:37.000Z","updated_at":"2026-03-30T13:25:15.000Z","published_at":"2012-02-20T19:38: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\u003eGiven a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a element\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return the number of occurrences of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: NaNs are equal and there may be no occurrences of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[v = 1:10\\ne = 2\\noutput = 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":51246,"title":"Characterize the final state of another digit inventory sequence","description":null,"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: 370.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 185.217px; transform-origin: 407px 185.217px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.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: 49.7917px 7.91667px; transform-origin: 49.7917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCody Problems \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e46122\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 15.5583px 7.91667px; transform-origin: 15.5583px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46571\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e46571\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 264.525px 7.91667px; transform-origin: 264.525px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved a digit inventory sequence in which one term in the sequence describes the previous. For example, if one term is 411, the next would be 2114: two 1’s, one 4. For some starting numbers, the sequence reaches a steady state, but for others, the terms oscillate.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 210.283px 7.91667px; transform-origin: 210.283px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA different form of a digit inventory is formed by listing the counts of \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 7.00833px 7.91667px; transform-origin: 7.00833px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eall\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 158.325px 7.91667px; transform-origin: 158.325px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e digits—in the order 1-9 and 0—and concatenating them for the next term in the sequence. If the initial seed is 570, then the next three terms would be \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 130.9px 7.91667px; transform-origin: 130.9px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e0000101001, 3000000007, 0010001008\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 361.7px 7.91667px; transform-origin: 361.7px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe first term arises because 570 has zero 1s, 2s, 3s, and 4s; one 5; zero 6s, one 7; zero 8s and 9s; and one 0. The second term arises because the first has three 1s, seven 0s, and zero of everything else. If we continue to generate terms, we will find that the seventh and eighth terms will repeat. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.933px 7.91667px; transform-origin: 381.933px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAt first, I thought that this sequence always reaches a state in which these same two terms oscillate, but I have since found a few seeds that lead to a steady state. \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.817px 7.91667px; transform-origin: 381.817px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes a seed as a string and determines the number of the term at which the final state begins and the period of the repeated terms. Take the initial seed to be term 1. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 371.042px 7.91667px; transform-origin: 371.042px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOptional: The function is not required to return the terms themselves, but the terms in the final state are interesting. The seeds in the test suite lead to only two sets of final terms. Can you find seeds that lead to different final terms? \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [n,period] = digitInventory2(y1)\r\n  n = f1(y1);\r\n  period = f2(y1);\r\nend","test_suite":"%%\r\ny1 = '1';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '53';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '100';\r\nn_correct = 6;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '570';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1000';\r\nn_correct = 6;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1002';\r\nn_correct = 5;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '10023';\r\nn_correct = 4;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '10234';\r\nn_correct = 8;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '11111';\r\nn_correct = 7;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '12345';\r\nn_correct = 8;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '11233344';\r\nn_correct = 4;\r\nperiod_correct = 1;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '112233344';\r\nn_correct = 4;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '11223334444';\r\nn_correct = 4;\r\nperiod_correct = 1;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '112233344445';\r\nn_correct = 6;\r\nperiod_correct = 1;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1111111111';\r\nn_correct = 8;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '1234567890';\r\nn_correct = 9;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = '122333444455555666666777777788888888999999999';\r\nn_correct = 10;\r\nperiod_correct = 2;\r\n[n,period] = digitInventory2(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2021-03-27T22:51:08.000Z","updated_at":"2025-12-16T21:32:44.000Z","published_at":"2021-03-27T23:42:35.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\u003eCody Problems \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\\\"\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e46122\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46571\\\"\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e46571\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e involved a digit inventory sequence in which one term in the sequence describes the previous. For example, if one term is 411, the next would be 2114: two 1’s, one 4. For some starting numbers, the sequence reaches a steady state, but for others, the terms oscillate.\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 different form of a digit inventory is formed by listing the counts of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e digits—in the order 1-9 and 0—and concatenating them for the next term in the sequence. If the initial seed is 570, then the next three terms 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[0000101001, 3000000007, 0010001008]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first term arises because 570 has zero 1s, 2s, 3s, and 4s; one 5; zero 6s, one 7; zero 8s and 9s; and one 0. The second term arises because the first has three 1s, seven 0s, and zero of everything else. If we continue to generate terms, we will find that the seventh and eighth terms will repeat. \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\u003eAt first, I thought that this sequence always reaches a state in which these same two terms oscillate, but I have since found a few seeds that lead to a steady state. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes a seed as a string and determines the number of the term at which the final state begins and the period of the repeated terms. Take the initial seed to be term 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\u003eOptional: The function is not required to return the terms themselves, but the terms in the final state are interesting. The seeds in the test suite lead to only two sets of final terms. Can you find seeds that lead to different final terms? \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":46571,"title":"Characterize the final state of the digit inventory sequence","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 317.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 158.65px; transform-origin: 407px 158.65px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCody Problem 46122\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 313.533px 7.91667px; transform-origin: 313.533px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved a counting sequence that I called the digit inventory sequence, in which each term provides an inventory of the digits of the previous term. If the initial number of the sequence is 24, then the sequence is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 304.15px 7.91667px; transform-origin: 304.15px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 265.65px 7.91667px; transform-origin: 265.65px 7.91667px; \"\u003e   24, 1214, 211214, 312214, 21221314, 31321314, 31123314, 31123314, \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 11.55px 7.91667px; text-decoration: none; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 11.55px 7.91667px; \"\u003e...\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(2, 128, 9); border-block-start-color: rgb(2, 128, 9); border-bottom-color: rgb(2, 128, 9); border-inline-end-color: rgb(2, 128, 9); border-inline-start-color: rgb(2, 128, 9); border-left-color: rgb(2, 128, 9); border-right-color: rgb(2, 128, 9); border-top-color: rgb(2, 128, 9); caret-color: rgb(2, 128, 9); color: rgb(2, 128, 9); column-rule-color: rgb(2, 128, 9); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(2, 128, 9); perspective-origin: 26.95px 7.91667px; text-decoration: none; text-decoration-color: rgb(2, 128, 9); text-emphasis-color: rgb(2, 128, 9); transform-origin: 26.95px 7.91667px; \"\u003e       \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 7.91667px; transform-origin: 384px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the third term provides an inventory of the second: two 1's, one 2, one 4. Notice that starting with 24 leads to a steady state after 7 terms because all subsequent terms are equal to the seventh (i.e., 31123314). \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 136.133px 7.91667px; transform-origin: 136.133px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHowever, the final state is not necessarily a \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 20.6167px 7.91667px; transform-origin: 20.6167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003esteady\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 178.125px 7.91667px; transform-origin: 178.125px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e state. If the starting number is 210, then the sequence is \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 20.4333px; transform-origin: 404px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 331.1px 7.91667px; transform-origin: 331.1px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   210, 101112, 104112, 10311214, 1041121314, 1051121324, 104122131415, 105122132415, \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 292.6px 7.91667px; transform-origin: 292.6px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 281.05px 7.91667px; transform-origin: 281.05px 7.91667px; \"\u003e   104132131425, 104122232415, 103142132415, 104122232415, 103142132415, \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 11.55px 7.91667px; text-decoration: none; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 11.55px 7.91667px; \"\u003e...\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 7.91667px; transform-origin: 384px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe tenth and eleventh terms repeat indefinitely. In other words, the repeated terms start at term 10, and they have a period of 2. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 372.875px 7.91667px; transform-origin: 372.875px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine the number of the term at which the final state begins and the period of the repeated terms.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 7.91667px; transform-origin: 0px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [n,period] = digInvFinalState(y1)\r\n  n = f1(y1);\r\n  period = f2(y1);\r\nend","test_suite":"%%\r\ny1 = 24;\r\nn_correct = 7;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 210;\r\nn_correct = 10;\r\nperiod_correct = 2;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 1;\r\nn_correct = 13;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 10;\r\nn_correct = 10;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 22;\r\nn_correct = 1;\r\nperiod_correct = 1;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 40;\r\nn_correct = 10;\r\nperiod_correct = 2;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\ny1 = 50;\r\nn_correct = 11;\r\nperiod_correct = 3;\r\n[n,period] = digInvFinalState(y1);\r\nassert(isequal(n,n_correct) \u0026\u0026 isequal(period,period_correct))\r\n\r\n%%\r\nfor y1 = 567:571\r\n    [n(y1-566),period(y1-566)] = digInvFinalState(y1);\r\nend\r\nprod_correct = 136;\r\nassert(isequal(n*period',prod_correct));","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-08-29T02:58:19.000Z","updated_at":"2025-12-16T21:25:08.000Z","published_at":"2020-08-29T04:10: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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46122-find-the-nth-term-in-the-digit-inventory-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody Problem 46122\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involved a counting sequence that I called the digit inventory sequence, in which each term provides an inventory of the digits of the previous term. If the initial number of the sequence is 24, then the sequence is\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   24, 1214, 211214, 312214, 21221314, 31321314, 31123314, 31123314, ...       ]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, the third term provides an inventory of the second: two 1's, one 2, one 4. Notice that starting with 24 leads to a steady state after 7 terms because all subsequent terms are equal to the seventh (i.e., 31123314). \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\u003eHowever, the final state is not necessarily a \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esteady\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e state. If the starting number is 210, then the sequence is \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   210, 101112, 104112, 10311214, 1041121314, 1051121324, 104122131415, 105122132415, \\n   104132131425, 104122232415, 103142132415, 104122232415, 103142132415, ...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe tenth and eleventh terms repeat indefinitely. In other words, the repeated terms start at term 10, and they have a period of 2. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine the number of the term at which the final state begins and the period of the repeated terms.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":45578,"title":"Create a matrix that counts up diagonally","description":"Given a single input _N_, create a _N_ x _N_ matrix that counts from 1 : _N_ ², (along up-right diagonals, starting with 1 in the top left corner. For example, given N=4...\r\n\r\n  1  3  6 10\r\n  2  5  9 13 \r\n  4  8 12 15 \r\n  7 11 14 16\r\n  \r\n\r\nNotice as you move up a row and right a column (↗) the values always increase by one. The value '1' should always go in the top left corner, with '2' directly below it. From there fill in the upward-rightward diagonals with the next higher integer until the matrix is complete. Assume N will always be a positive integer greater than 1 (N \u003e= 2).\r\n","description_html":"\u003cp\u003eGiven a single input \u003ci\u003eN\u003c/i\u003e, create a \u003ci\u003eN\u003c/i\u003e x \u003ci\u003eN\u003c/i\u003e matrix that counts from 1 : \u003ci\u003eN\u003c/i\u003e ², (along up-right diagonals, starting with 1 in the top left corner. For example, given N=4...\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1  3  6 10\r\n2  5  9 13 \r\n4  8 12 15 \r\n7 11 14 16\r\n\u003c/pre\u003e\u003cp\u003eNotice as you move up a row and right a column (↗) the values always increase by one. The value '1' should always go in the top left corner, with '2' directly below it. From there fill in the upward-rightward diagonals with the next higher integer until the matrix is complete. Assume N will always be a positive integer greater than 1 (N \u0026gt;= 2).\u003c/p\u003e","function_template":"function mx = not_hankel(N)\r\n\r\n    mx = ones(N); %replace with your code\r\n\r\nend","test_suite":"%%\r\nN = 20;\r\n\r\nmx_correct = [...\r\n     1     3     6    10    15    21    28    36    45    55    66    78    91   105   120   136   153   171   190   210\r\n     2     5     9    14    20    27    35    44    54    65    77    90   104   119   135   152   170   189   209   229\r\n     4     8    13    19    26    34    43    53    64    76    89   103   118   134   151   169   188   208   228   247\r\n     7    12    18    25    33    42    52    63    75    88   102   117   133   150   168   187   207   227   246   264\r\n    11    17    24    32    41    51    62    74    87   101   116   132   149   167   186   206   226   245   263   280\r\n    16    23    31    40    50    61    73    86   100   115   131   148   166   185   205   225   244   262   279   295\r\n    22    30    39    49    60    72    85    99   114   130   147   165   184   204   224   243   261   278   294   309\r\n    29    38    48    59    71    84    98   113   129   146   164   183   203   223   242   260   277   293   308   322\r\n    37    47    58    70    83    97   112   128   145   163   182   202   222   241   259   276   292   307   321   334\r\n    46    57    69    82    96   111   127   144   162   181   201   221   240   258   275   291   306   320   333   345\r\n    56    68    81    95   110   126   143   161   180   200   220   239   257   274   290   305   319   332   344   355\r\n    67    80    94   109   125   142   160   179   199   219   238   256   273   289   304   318   331   343   354   364\r\n    79    93   108   124   141   159   178   198   218   237   255   272   288   303   317   330   342   353   363   372\r\n    92   107   123   140   158   177   197   217   236   254   271   287   302   316   329   341   352   362   371   379\r\n   106   122   139   157   176   196   216   235   253   270   286   301   315   328   340   351   361   370   378   385\r\n   121   138   156   175   195   215   234   252   269   285   300   314   327   339   350   360   369   377   384   390\r\n   137   155   174   194   214   233   251   268   284   299   313   326   338   349   359   368   376   383   389   394\r\n   154   173   193   213   232   250   267   283   298   312   325   337   348   358   367   375   382   388   393   397\r\n   172   192   212   231   249   266   282   297   311   324   336   347   357   366   374   381   387   392   396   399\r\n   191   211   230   248   265   281   296   310   323   335   346   356   365   373   380   386   391   395   398   400\r\n   ];\r\n\r\nassert(isequal(not_hankel(N),mx_correct))\r\n\r\n\r\n\r\n%%\r\nN = 3;\r\n\r\nmx_correct = [...\r\n     1     3     6\r\n     2     5     8\r\n     4     7     9\r\n     ];\r\n\r\nassert(isequal(not_hankel(N),mx_correct))\r\n\r\n\r\n\r\n%%\r\nrng('shuffle')\r\nN  = randi(99)+5;\r\nr = repmat((0:(N-1))',1,N) + (0:(N-1));\r\np = ((.5.*r.^2 + .5.*r) + (r(1,:)+1));\r\nq = rot90(hankel(fliplr(0:N-1)),2).^2;\r\nmx_correct = p - q;\r\nassert(isequal(not_hankel(N),mx_correct))\r\n\r\n\r\n\r\n%% \r\nN = 2;\r\nmx_correct =...\r\n[...\r\n    1  3\r\n    2  4 \r\n];\r\n\r\nassert(isequal(not_hankel(N),mx_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":18354,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":22,"test_suite_updated_at":"2020-05-22T17:05:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-22T16:46:56.000Z","updated_at":"2026-01-20T13:24:26.000Z","published_at":"2020-05-22T16:46: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 single input\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, create 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e x\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix that counts from 1 :\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ², (along up-right diagonals, starting with 1 in the top left corner. For example, given N=4...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1  3  6 10\\n2  5  9 13 \\n4  8 12 15 \\n7 11 14 16]]\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\u003eNotice as you move up a row and right a column (↗) the values always increase by one. The value '1' should always go in the top left corner, with '2' directly below it. From there fill in the upward-rightward diagonals with the next higher integer until the matrix is complete. Assume N will always be a positive integer greater than 1 (N \u0026gt;= 2).\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":42787,"title":"How many ways to write ","description":"How many ways to write a positive integer x as the sum of n numbers , where , x\u003en and no n number is less than -2.","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: 361px 8px; transform-origin: 361px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHow many ways to write a positive integer x as the sum of n numbers , where , x\u0026gt;n and no n number is less than -2.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x,n)\r\n  y = x+n;\r\nend","test_suite":"%%\r\nx=1;\r\nn=2;\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=7;\r\nn=3;\r\ny_correct = 66;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=40;\r\nn=7;\r\ny_correct =277962685 ;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=40;\r\nn=4;\r\ny_correct =79079;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":20,"created_by":65236,"edited_by":223089,"edited_at":"2023-02-07T10:08:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2023-02-07T10:08:32.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-27T16:59:02.000Z","updated_at":"2025-12-16T04:49:04.000Z","published_at":"2016-03-27T16:59:02.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHow many ways to write a positive integer x as the sum of n numbers , where , x\u0026gt;n and no n number is less than -2.\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\"}]}"}],"term":"tag:\"counting\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"counting\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"counting\"","","\"","counting","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d9d803d8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d9d80338\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d9d9fa08\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d9d80658\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d9d805b8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d9d80518\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d9d80478\u003e":"tag:\"counting\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d9d80478\u003e":"tag:\"counting\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"counting\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"counting\"","","\"","counting","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d9d803d8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d9d80338\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d9d9fa08\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d9d80658\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d9d805b8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d9d80518\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d9d80478\u003e":"tag:\"counting\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d9d80478\u003e":"tag:\"counting\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":43639,"difficulty_rating":"easy"},{"id":341,"difficulty_rating":"easy"},{"id":1290,"difficulty_rating":"easy-medium"},{"id":107,"difficulty_rating":"easy-medium"},{"id":42788,"difficulty_rating":"easy-medium"},{"id":367,"difficulty_rating":"easy-medium"},{"id":51246,"difficulty_rating":"easy-medium"},{"id":46571,"difficulty_rating":"medium"},{"id":45578,"difficulty_rating":"medium"},{"id":42787,"difficulty_rating":"hard"}]}}