{"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":42863,"title":"Replace values out of an interval with the lower or upper values","description":"For a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\r\n\r\nExample\r\n\r\n x= [1 2 3 4 5 1 2 4 6]\r\n\r\n n=[3,5]\r\n\r\n y_correct= [3 3 3 4 5 3 3 4 5]","description_html":"\u003cp\u003eFor a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x= [1 2 3 4 5 1 2 4 6]\u003c/pre\u003e\u003cpre\u003e n=[3,5]\u003c/pre\u003e\u003cpre\u003e y_correct= [3 3 3 4 5 3 3 4 5]\u003c/pre\u003e","function_template":"function y = limit2interval(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = ones(1,25);\r\nn=[0,2];\r\ny_correct = x;\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= [1 2 3 4 5 1 2 4 6];\r\nn=[3,5];\r\ny_correct= [3 3 3 4 5 3 3 4 5];\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= magic(7);\r\nn=[7,14];\r\ny_correct=ones(7)*14-sparse([4 5 3 2 3 1 2 1 7 6 7 5 6],[1 1 2 3 3 4 4 5 5 6 6 7 7],[7 1 7 7 6 7 5 4 7 7 3 7 2])\r\nassert(isequal(limit2interval(x,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":55194,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":71,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-05-28T10:47:32.000Z","updated_at":"2026-02-04T15:47:26.000Z","published_at":"2016-05-28T21:13:31.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x= [1 2 3 4 5 1 2 4 6]\\n\\n n=[3,5]\\n\\n y_correct= [3 3 3 4 5 3 3 4 5]]]\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":1838,"title":"Min of a Matrix","description":"Return the minimum value in the given matrix.","description_html":"\u003cp\u003eReturn the minimum value in the given matrix.\u003c/p\u003e","function_template":"function y = matrixMin(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6; 7 8 9;];\r\ny_correct = 1;\r\nassert(isequal(matrixMin(x),y_correct))\r\n\r\n%%\r\nx = [42 35 18 9; 28 92 11 444; 8 12 9 111];\r\ny_correct = 8;\r\nassert(isequal(matrixMin(x),y_correct));\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":1,"created_by":16420,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":759,"test_suite_updated_at":"2013-08-19T18:54:37.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-19T18:50:01.000Z","updated_at":"2026-02-24T00:54:24.000Z","published_at":"2013-08-19T18:50:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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 the minimum value in the given matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":49647,"title":"Original coordinate of the min element of a subset of elements","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; 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 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFind the smallest element in a subset (marked by a logical matrix) of the given matrix, return its coordinate in the original matrix. Ignore NaN elements.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [Row,Column] = MinCoordinateOfSubset(OriginalMatrix,SubsetMarker)\r\n  Row=0;\r\n  Column=0;\r\nend","test_suite":"%%\r\nOriginalMatrix= [   60    40   NaN   NaN   NaN   NaN\r\n    20   NaN   NaN    20    80   NaN\r\n   NaN   NaN   100    40   NaN   NaN\r\n   NaN    80   NaN   NaN   NaN   NaN\r\n    20   NaN   NaN   NaN   NaN    40];\r\nSubsetMarker=logical([   0   1   0   0   0   0\r\n   1   0   0   0   0   0\r\n   0   0   0   1   0   0\r\n   0   0   0   0   0   0\r\n   0   0   0   0   0   0]);\r\n[Row,Column]=MinCoordinateOfSubset(OriginalMatrix,SubsetMarker);\r\nassert(Row==2\u0026\u0026Column==1);\r\n%%\r\nOriginalMatrix=[    0.7948    0.9390       NaN    0.1707       NaN    0.4087\r\n    0.6443       NaN    0.4709    0.2277    0.9049    0.5949\r\n    0.3786    0.5502    0.2305       NaN       NaN       NaN\r\n    0.8116       NaN       NaN       NaN       NaN    0.6028\r\n       NaN       NaN       NaN    0.9234       NaN       NaN\r\n    0.3507    0.2077       NaN    0.4302    0.2581    0.2217];\r\nSubsetMarker=logical( [   1   1   0   0   0   0\r\n   1   1   0   1   0   0\r\n   0   0   0   0   1   0\r\n   1   0   1   1   0   1\r\n   1   1   1   1   0   1\r\n   1   0   0   0   0   0]);\r\n[Row,Column]=MinCoordinateOfSubset(OriginalMatrix,SubsetMarker);\r\nassert(Row==2\u0026\u0026Column==4);","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":362068,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-28T08:28:17.000Z","updated_at":"2026-01-20T14:03:31.000Z","published_at":"2020-12-28T08:28:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the smallest element in a subset (marked by a logical matrix) of the given matrix, return its coordinate in the original matrix. Ignore NaN elements.\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":45409,"title":"MinMax mapping","description":"Given a matrix, map all the elements within a given interval.\r\n\r\nFor example,\r\n \r\n  a=[ 2 5 10]\r\n  mapped in the interval [1,2]  \u003e\u003e  [1, 1.375, 2].","description_html":"\u003cp\u003eGiven a matrix, map all the elements within a given interval.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea=[ 2 5 10]\r\nmapped in the interval [1,2]  \u0026gt;\u0026gt;  [1, 1.375, 2].\r\n\u003c/pre\u003e","function_template":"function y = minmax_map(x,l,h)","test_suite":"%%\r\nx = [ 2 5 10];\r\ny =[1, 1.375, 2];\r\nassert(isequal(minmax_map(x,1,2),y))\r\n\r\n%%\r\nx=[-5 3 -65 -55 34 555 3 2 0 -5];\r\ny =[ 187.1       198.71          100       114.52       243.71\t 1000       198.71       197.26       194.35        187.1];\r\nz=abs(minmax_map(x,100,1000)-y)\u003c0.01\r\nassert(all(z))\r\n\r\n%%\r\nx = magic(3);\r\ny =[24     3    18\r\n     9    15    21\r\n    12    27     6];\r\nassert(isequal(minmax_map(x,3,27),y))\r\n\r\n%%\r\nx = pascal(5);\r\ny =[-100         -100         -100         -100         -100\r\n         -100      -97.101      -94.203      -91.304      -88.406\r\n         -100      -94.203      -85.507      -73.913       -59.42\r\n         -100      -91.304      -73.913      -44.928      -1.4493\r\n         -100      -88.406       -59.42      -1.4493          100];\r\nz=abs(minmax_map(x,-100,100)-y)\u003c0.01\r\nassert(all(z,'all'))\r\n\r\n%%\r\nx=eye(5);\r\ny=[55     5     5     5     5\r\n     5    55     5     5     5\r\n     5     5    55     5     5\r\n     5     5     5    55     5\r\n     5     5     5     5    55];\r\n \r\n assert(isequal(minmax_map(x,5,55),y))\r\n \r\n %%\r\n x=[4 -5 -55 -555 34; 34 34 34 -66 2];\r\n y=[1.4745       1.4669       1.4244            1          1.5\r\n          1.5          1.5          1.5       1.4151       1.4728]\r\n   z=abs(minmax_map(x,1,1.5)-y)\u003c0.01\r\nassert(all(z,'all'))   ","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":"2020-03-31T04:11:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-31T02:55:22.000Z","updated_at":"2026-01-03T15:50:10.000Z","published_at":"2020-03-31T03:46:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix, map all the elements within a given interval.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[a=[ 2 5 10]\\nmapped in the interval [1,2]  \u003e\u003e  [1, 1.375, 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":45394,"title":"Count the number of folds needed to pack a large sheet","description":"In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\r\n\r\n# Lay down a large sheet of paper of size X-by-Y feet.\r\n# _Fold_ the sheet in half so that the _larger_ length between X and Y is halved and the other length remains the same.\r\n# Repeat step 2 until _both_ lengths X and Y are _less_ than 1 foot.\r\n\r\nFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u003c= X \u003c= 4000 and 1 \u003c= Y \u003c= 4000. \r\n\r\nAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u003e (4,2.5) -\u003e (2,2.5) -\u003e (2,1.25) -\u003e (1,1.25) -\u003e (1,0.625) -\u003e (0.5,0.625). We stop because _both_ sizes are now less than 1. This takes a total of 6 folds.","description_html":"\u003cp\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/p\u003e\u003col\u003e\u003cli\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/li\u003e\u003cli\u003e\u003ci\u003eFold\u003c/i\u003e the sheet in half so that the \u003ci\u003elarger\u003c/i\u003e length between X and Y is halved and the other length remains the same.\u003c/li\u003e\u003cli\u003eRepeat step 2 until \u003ci\u003eboth\u003c/i\u003e lengths X and Y are \u003ci\u003eless\u003c/i\u003e than 1 foot.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/p\u003e\u003cp\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because \u003ci\u003eboth\u003c/i\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/p\u003e","function_template":"function y = number_of_folds(X,Y)\r\n  y = X;\r\nend","test_suite":"%%\r\nassert(isequal(number_of_folds(3247,2132),24))\r\n%%\r\nassert(isequal(number_of_folds(1403,3757),23))\r\n%%\r\nassert(isequal(number_of_folds(3504,2201),24))\r\n%%\r\nassert(isequal(number_of_folds(2490,2349),24))\r\n%%\r\nassert(isequal(number_of_folds(831,1205),21))\r\n%%\r\nassert(isequal(number_of_folds(1884,922),21))\r\n%%\r\nassert(isequal(number_of_folds(2,4),5))\r\n%%\r\nassert(isequal(number_of_folds(3378,780),22))\r\n%%\r\nassert(isequal(number_of_folds(904,683),20))\r\n%%\r\nassert(isequal(number_of_folds(911,1743),21))\r\n%%\r\nassert(isequal(number_of_folds(1245,3694),23))\r\n%%\r\nassert(isequal(number_of_folds(1721,740),21))\r\n%%\r\nassert(isequal(number_of_folds(3620,3919),24))\r\n%%\r\nassert(isequal(number_of_folds(1756,445),20))\r\n%%\r\nassert(isequal(number_of_folds(1033,1635),22))\r\n%%\r\nassert(isequal(number_of_folds(2380,1049),23))\r\n%%\r\nassert(isequal(number_of_folds(2412,2845),24))\r\n%%\r\nassert(isequal(number_of_folds(887,470),19))\r\n%%\r\nassert(isequal(number_of_folds(1187,1276),22))\r\n%%\r\nassert(isequal(number_of_folds(1697,2032),22))\r\n%%\r\nassert(isequal(number_of_folds(343,1050),20))\r\n%%\r\nassert(isequal(number_of_folds(3205,117),19))\r\n%%\r\nassert(isequal(number_of_folds(3716,2922),24))\r\n%%\r\nassert(isequal(number_of_folds(1955,2315),23))\r\n%%\r\nassert(isequal(number_of_folds(950,1836),21))\r\n%%\r\nassert(isequal(number_of_folds(3853,2188),24))\r\n%%\r\nassert(isequal(number_of_folds(2085,927),22))\r\n%%\r\nassert(isequal(number_of_folds(1956,2497),23))\r\n%%\r\nassert(isequal(number_of_folds(2717,1583),23))\r\n%%\r\nassert(isequal(number_of_folds(1470,3952),23))\r\n%%\r\nassert(isequal(number_of_folds(151,3541),20))\r\n%%\r\nassert(isequal(number_of_folds(3654,3185),24))\r\n%%\r\nassert(isequal(number_of_folds(395,1048),20))\r\n%%\r\nassert(isequal(number_of_folds(1342,2719),23))\r\n%%\r\nassert(isequal(number_of_folds(547,2885),22))\r\n%%\r\nassert(isequal(number_of_folds(428,2616),21))\r\n%%\r\nassert(isequal(number_of_folds(1977,3117),23))\r\n%%\r\nassert(isequal(number_of_folds(2861,3615),24))\r\n%%\r\nassert(isequal(number_of_folds(3564,1337),23))\r\n%%\r\nassert(isequal(number_of_folds(1,4000),13))\r\n%%\r\nassert(isequal(number_of_folds(2795,792),22))\r\n%%\r\nassert(isequal(number_of_folds(123,2977),19))\r\n%%\r\nassert(isequal(number_of_folds(2001,1920),22))\r\n%%\r\nassert(isequal(number_of_folds(3619,2440),24))\r\n%%\r\nassert(isequal(number_of_folds(2471,3438),24))\r\n%%\r\nassert(isequal(number_of_folds(3222,2307),24))\r\n%%\r\nassert(isequal(number_of_folds(732,960),20))\r\n%%\r\nassert(isequal(number_of_folds(3547,115),19))\r\n%%\r\nassert(isequal(number_of_folds(1960,672),21))\r\n%%\r\nassert(isequal(number_of_folds(3915,2851),24))\r\n%%\r\nassert(isequal(number_of_folds(2002,1885),22))\r\n%%\r\nassert(isequal(number_of_folds(239,2728),20))\r\n%%\r\nassert(isequal(number_of_folds(170,286),17))\r\n%%\r\nassert(isequal(number_of_folds(2087,387),21))\r\n%%\r\nassert(isequal(number_of_folds(3273,3271),24))\r\n%%\r\nassert(isequal(number_of_folds(2890,600),22))\r\n%%\r\nassert(isequal(number_of_folds(2639,2075),24))\r\n%%\r\nassert(isequal(number_of_folds(3892,2596),24))\r\n%%\r\nassert(isequal(number_of_folds(3202,1816),23))\r\n%%\r\nassert(isequal(number_of_folds(1730,3302),23))\r\n%%\r\nassert(isequal(number_of_folds(334,533),19))\r\n%%\r\nassert(isequal(number_of_folds(694,1564),21))\r\n%%\r\nassert(isequal(number_of_folds(3326,3214),24))\r\n%%\r\nassert(isequal(number_of_folds(242,1598),19))\r\n%%\r\nassert(isequal(number_of_folds(2108,1668),23))\r\n%%\r\nassert(isequal(number_of_folds(2628,2512),24))\r\n%%\r\nassert(isequal(number_of_folds(1168,1727),22))\r\n%%\r\nassert(isequal(number_of_folds(62,3937),18))\r\n%%\r\nassert(isequal(number_of_folds(669,425),19))\r\n%%\r\nassert(isequal(number_of_folds(1490,793),21))\r\n%%\r\nassert(isequal(number_of_folds(1959,1358),22))\r\n%%\r\nassert(isequal(number_of_folds(3807,3682),24))\r\n%%\r\nassert(isequal(number_of_folds(211,2952),20))\r\n%%\r\nassert(isequal(number_of_folds(1077,1692),22))\r\n%%\r\nassert(isequal(number_of_folds(2192,3771),24))\r\n%%\r\nassert(isequal(number_of_folds(1,1),2))\r\n%%\r\nassert(isequal(number_of_folds(1671,3933),23))\r\n%%\r\nassert(isequal(number_of_folds(1206,2805),23))\r\n%%\r\nassert(isequal(number_of_folds(2666,2157),24))\r\n%%\r\nassert(isequal(number_of_folds(2793,2667),24))\r\n%%\r\nassert(isequal(number_of_folds(713,513),20))\r\n%%\r\nassert(isequal(number_of_folds(3997,685),22))\r\n%%\r\nassert(isequal(number_of_folds(131,2245),20))\r\n%%\r\nassert(isequal(number_of_folds(3528,2677),24))\r\n%%\r\nassert(isequal(number_of_folds(762,1476),21))\r\n%%\r\nassert(isequal(number_of_folds(1843,3927),23))\r\n%%\r\nassert(isequal(number_of_folds(626,3423),22))\r\n%%\r\nassert(isequal(number_of_folds(2580,1506),23))\r\n%%\r\nassert(isequal(number_of_folds(764,1714),21))\r\n%%\r\nassert(isequal(number_of_folds(1929,483),20))\r\n%%\r\nassert(isequal(number_of_folds(2359,905),22))\r\n%%\r\nassert(isequal(number_of_folds(1539,2332),23))\r\n%%\r\nassert(isequal(number_of_folds(1008,1162),21))\r\n%%\r\nassert(isequal(number_of_folds(2469,1062),23))\r\n%%\r\nassert(isequal(number_of_folds(15,15),8))\r\n%%\r\nassert(isequal(number_of_folds(3298,3931),24))\r\n%%\r\nassert(isequal(number_of_folds(2921,1376),23))\r\n%%\r\nassert(isequal(number_of_folds(2337,432),21))\r\n%%\r\nassert(isequal(number_of_folds(3626,3519),24))\r\n%%\r\nassert(isequal(number_of_folds(3272,1043),23))\r\n%%\r\nassert(isequal(number_of_folds(3,2),4))\r\n%%\r\nassert(isequal(number_of_folds(2378,91),19))\r\n%%\r\nassert(isequal(number_of_folds(1702,1251),22))\r\n%%\r\nassert(isequal(number_of_folds(646,716),20))\r\n%%\r\nassert(isequal(number_of_folds(1692,377),20))\r\n%%\r\nassert(isequal(number_of_folds(16,15),9))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":115,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-26T22:22:34.000Z","updated_at":"2026-03-31T14:22:20.000Z","published_at":"2020-03-26T22:22:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFold\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the sheet in half so that the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elarger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e length between X and Y is halved and the other length remains the same.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRepeat step 2 until\u003c/w:t\u003e\u003c/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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e lengths X and Y 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eless\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e than 1 foot.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because\u003c/w:t\u003e\u003c/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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e sizes are now less than 1. This takes a total of 6 folds.\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":42634,"title":"Minimum of each diagonal","description":"The well-known \u003chttp://www.mathworks.com/help/matlab/ref/min.html min\u003e function can operate along either the rows or the columns of a matrix by using\r\n\r\n  [Y,I] = min(X,[],1) or [Y,I] = min(X,[],2)\r\n\r\nbut it cannot operate along a diagonal dimension. For this problem, create a function that returns the smallest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\r\n\r\n*Example*\r\n\r\nIf \r\n\r\n  X = magic(3) = [8 1 6\r\n                  3 5 7\r\n                  4 9 2]\r\n\r\nthen\r\n\r\n  Y = mindiag(X) = [4 3 2 1 6]\r\n\r\nSee also \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42635-maximum-of-each-diagonal maxdiag\u003e.","description_html":"\u003cp\u003eThe well-known \u003ca href = \"http://www.mathworks.com/help/matlab/ref/min.html\"\u003emin\u003c/a\u003e function can operate along either the rows or the columns of a matrix by using\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[Y,I] = min(X,[],1) or [Y,I] = min(X,[],2)\r\n\u003c/pre\u003e\u003cp\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the smallest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eX = magic(3) = [8 1 6\r\n                3 5 7\r\n                4 9 2]\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eY = mindiag(X) = [4 3 2 1 6]\r\n\u003c/pre\u003e\u003cp\u003eSee also \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42635-maximum-of-each-diagonal\"\u003emaxdiag\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = mindiag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isempty(mindiag([])))\r\n\r\n%%\r\nx = randi(100);\r\nassert(isequal(mindiag(x),x))\r\n\r\n%%\r\nx = randi(100,100,1);\r\nassert(isequal(mindiag(x),x(end:-1:1)'))\r\n\r\n%%\r\nx = randi(100,1,100);\r\nassert(isequal(mindiag(x),x))\r\n\r\n%%\r\nx = eye(2);\r\nassert(isequal(mindiag(x),[0 1 0]))\r\n\r\n%%\r\nx = magic(3);\r\nassert(isequal(mindiag(x),[4 3 2 1 6]))\r\n\r\n%%\r\nx = flipud(hankel(1:1000));\r\nassert(isequal(mindiag(x),[1:1000,zeros(1,1000-1)]))\r\n\r\n%%\r\nx = toeplitz(1:1000);\r\nassert(isequal(mindiag(x),[1000:-1:1,2:1000]))\r\n\r\n%%\r\nN = randi(1000);\r\nx = fliplr(toeplitz(1:N));\r\ny = ones(1,2*N-1);\r\ny(2:2:end) = 2;\r\nassert(isequal(mindiag(x),y))\r\n\r\n%%\r\nx = magic(10);\r\nx = x(:,1:3);\r\nassert(isequal(mindiag(x),[11 10 12 6 5 24 76 4 19 80 7 1]))\r\n\r\n%%\r\nx = hankel(-4:0,0:-2:-16);\r\nassert(isequal(mindiag(x),[0 -2 -4 -6 -8 -10 -12 -14 -16 -14 -12 -10 -8]))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":"2015-09-23T23:03:11.000Z","rescore_all_solutions":false,"group_id":24,"created_at":"2015-09-23T23:00:02.000Z","updated_at":"2026-04-01T07:12:19.000Z","published_at":"2015-09-23T23:00:02.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe well-known\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/min.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emin\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e function can operate along either the rows or the columns of a matrix by using\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[Y,I] = min(X,[],1) or [Y,I] = min(X,[],2)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the smallest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[X = magic(3) = [8 1 6\\n                3 5 7\\n                4 9 2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Y = mindiag(X) = [4 3 2 1 6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42635-maximum-of-each-diagonal\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emaxdiag\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":42863,"title":"Replace values out of an interval with the lower or upper values","description":"For a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\r\n\r\nExample\r\n\r\n x= [1 2 3 4 5 1 2 4 6]\r\n\r\n n=[3,5]\r\n\r\n y_correct= [3 3 3 4 5 3 3 4 5]","description_html":"\u003cp\u003eFor a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x= [1 2 3 4 5 1 2 4 6]\u003c/pre\u003e\u003cpre\u003e n=[3,5]\u003c/pre\u003e\u003cpre\u003e y_correct= [3 3 3 4 5 3 3 4 5]\u003c/pre\u003e","function_template":"function y = limit2interval(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = ones(1,25);\r\nn=[0,2];\r\ny_correct = x;\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= [1 2 3 4 5 1 2 4 6];\r\nn=[3,5];\r\ny_correct= [3 3 3 4 5 3 3 4 5];\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= magic(7);\r\nn=[7,14];\r\ny_correct=ones(7)*14-sparse([4 5 3 2 3 1 2 1 7 6 7 5 6],[1 1 2 3 3 4 4 5 5 6 6 7 7],[7 1 7 7 6 7 5 4 7 7 3 7 2])\r\nassert(isequal(limit2interval(x,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":55194,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":71,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-05-28T10:47:32.000Z","updated_at":"2026-02-04T15:47:26.000Z","published_at":"2016-05-28T21:13:31.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x= [1 2 3 4 5 1 2 4 6]\\n\\n n=[3,5]\\n\\n y_correct= [3 3 3 4 5 3 3 4 5]]]\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":1838,"title":"Min of a Matrix","description":"Return the minimum value in the given matrix.","description_html":"\u003cp\u003eReturn the minimum value in the given matrix.\u003c/p\u003e","function_template":"function y = matrixMin(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6; 7 8 9;];\r\ny_correct = 1;\r\nassert(isequal(matrixMin(x),y_correct))\r\n\r\n%%\r\nx = [42 35 18 9; 28 92 11 444; 8 12 9 111];\r\ny_correct = 8;\r\nassert(isequal(matrixMin(x),y_correct));\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":1,"created_by":16420,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":759,"test_suite_updated_at":"2013-08-19T18:54:37.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-19T18:50:01.000Z","updated_at":"2026-02-24T00:54:24.000Z","published_at":"2013-08-19T18:50:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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 the minimum value in the given matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":49647,"title":"Original coordinate of the min element of a subset of elements","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; 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 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFind the smallest element in a subset (marked by a logical matrix) of the given matrix, return its coordinate in the original matrix. Ignore NaN elements.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [Row,Column] = MinCoordinateOfSubset(OriginalMatrix,SubsetMarker)\r\n  Row=0;\r\n  Column=0;\r\nend","test_suite":"%%\r\nOriginalMatrix= [   60    40   NaN   NaN   NaN   NaN\r\n    20   NaN   NaN    20    80   NaN\r\n   NaN   NaN   100    40   NaN   NaN\r\n   NaN    80   NaN   NaN   NaN   NaN\r\n    20   NaN   NaN   NaN   NaN    40];\r\nSubsetMarker=logical([   0   1   0   0   0   0\r\n   1   0   0   0   0   0\r\n   0   0   0   1   0   0\r\n   0   0   0   0   0   0\r\n   0   0   0   0   0   0]);\r\n[Row,Column]=MinCoordinateOfSubset(OriginalMatrix,SubsetMarker);\r\nassert(Row==2\u0026\u0026Column==1);\r\n%%\r\nOriginalMatrix=[    0.7948    0.9390       NaN    0.1707       NaN    0.4087\r\n    0.6443       NaN    0.4709    0.2277    0.9049    0.5949\r\n    0.3786    0.5502    0.2305       NaN       NaN       NaN\r\n    0.8116       NaN       NaN       NaN       NaN    0.6028\r\n       NaN       NaN       NaN    0.9234       NaN       NaN\r\n    0.3507    0.2077       NaN    0.4302    0.2581    0.2217];\r\nSubsetMarker=logical( [   1   1   0   0   0   0\r\n   1   1   0   1   0   0\r\n   0   0   0   0   1   0\r\n   1   0   1   1   0   1\r\n   1   1   1   1   0   1\r\n   1   0   0   0   0   0]);\r\n[Row,Column]=MinCoordinateOfSubset(OriginalMatrix,SubsetMarker);\r\nassert(Row==2\u0026\u0026Column==4);","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":362068,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-28T08:28:17.000Z","updated_at":"2026-01-20T14:03:31.000Z","published_at":"2020-12-28T08:28:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the smallest element in a subset (marked by a logical matrix) of the given matrix, return its coordinate in the original matrix. Ignore NaN elements.\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":45409,"title":"MinMax mapping","description":"Given a matrix, map all the elements within a given interval.\r\n\r\nFor example,\r\n \r\n  a=[ 2 5 10]\r\n  mapped in the interval [1,2]  \u003e\u003e  [1, 1.375, 2].","description_html":"\u003cp\u003eGiven a matrix, map all the elements within a given interval.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea=[ 2 5 10]\r\nmapped in the interval [1,2]  \u0026gt;\u0026gt;  [1, 1.375, 2].\r\n\u003c/pre\u003e","function_template":"function y = minmax_map(x,l,h)","test_suite":"%%\r\nx = [ 2 5 10];\r\ny =[1, 1.375, 2];\r\nassert(isequal(minmax_map(x,1,2),y))\r\n\r\n%%\r\nx=[-5 3 -65 -55 34 555 3 2 0 -5];\r\ny =[ 187.1       198.71          100       114.52       243.71\t 1000       198.71       197.26       194.35        187.1];\r\nz=abs(minmax_map(x,100,1000)-y)\u003c0.01\r\nassert(all(z))\r\n\r\n%%\r\nx = magic(3);\r\ny =[24     3    18\r\n     9    15    21\r\n    12    27     6];\r\nassert(isequal(minmax_map(x,3,27),y))\r\n\r\n%%\r\nx = pascal(5);\r\ny =[-100         -100         -100         -100         -100\r\n         -100      -97.101      -94.203      -91.304      -88.406\r\n         -100      -94.203      -85.507      -73.913       -59.42\r\n         -100      -91.304      -73.913      -44.928      -1.4493\r\n         -100      -88.406       -59.42      -1.4493          100];\r\nz=abs(minmax_map(x,-100,100)-y)\u003c0.01\r\nassert(all(z,'all'))\r\n\r\n%%\r\nx=eye(5);\r\ny=[55     5     5     5     5\r\n     5    55     5     5     5\r\n     5     5    55     5     5\r\n     5     5     5    55     5\r\n     5     5     5     5    55];\r\n \r\n assert(isequal(minmax_map(x,5,55),y))\r\n \r\n %%\r\n x=[4 -5 -55 -555 34; 34 34 34 -66 2];\r\n y=[1.4745       1.4669       1.4244            1          1.5\r\n          1.5          1.5          1.5       1.4151       1.4728]\r\n   z=abs(minmax_map(x,1,1.5)-y)\u003c0.01\r\nassert(all(z,'all'))   ","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":"2020-03-31T04:11:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-31T02:55:22.000Z","updated_at":"2026-01-03T15:50:10.000Z","published_at":"2020-03-31T03:46:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix, map all the elements within a given interval.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[a=[ 2 5 10]\\nmapped in the interval [1,2]  \u003e\u003e  [1, 1.375, 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":45394,"title":"Count the number of folds needed to pack a large sheet","description":"In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\r\n\r\n# Lay down a large sheet of paper of size X-by-Y feet.\r\n# _Fold_ the sheet in half so that the _larger_ length between X and Y is halved and the other length remains the same.\r\n# Repeat step 2 until _both_ lengths X and Y are _less_ than 1 foot.\r\n\r\nFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u003c= X \u003c= 4000 and 1 \u003c= Y \u003c= 4000. \r\n\r\nAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u003e (4,2.5) -\u003e (2,2.5) -\u003e (2,1.25) -\u003e (1,1.25) -\u003e (1,0.625) -\u003e (0.5,0.625). We stop because _both_ sizes are now less than 1. This takes a total of 6 folds.","description_html":"\u003cp\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/p\u003e\u003col\u003e\u003cli\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/li\u003e\u003cli\u003e\u003ci\u003eFold\u003c/i\u003e the sheet in half so that the \u003ci\u003elarger\u003c/i\u003e length between X and Y is halved and the other length remains the same.\u003c/li\u003e\u003cli\u003eRepeat step 2 until \u003ci\u003eboth\u003c/i\u003e lengths X and Y are \u003ci\u003eless\u003c/i\u003e than 1 foot.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/p\u003e\u003cp\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because \u003ci\u003eboth\u003c/i\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/p\u003e","function_template":"function y = number_of_folds(X,Y)\r\n  y = X;\r\nend","test_suite":"%%\r\nassert(isequal(number_of_folds(3247,2132),24))\r\n%%\r\nassert(isequal(number_of_folds(1403,3757),23))\r\n%%\r\nassert(isequal(number_of_folds(3504,2201),24))\r\n%%\r\nassert(isequal(number_of_folds(2490,2349),24))\r\n%%\r\nassert(isequal(number_of_folds(831,1205),21))\r\n%%\r\nassert(isequal(number_of_folds(1884,922),21))\r\n%%\r\nassert(isequal(number_of_folds(2,4),5))\r\n%%\r\nassert(isequal(number_of_folds(3378,780),22))\r\n%%\r\nassert(isequal(number_of_folds(904,683),20))\r\n%%\r\nassert(isequal(number_of_folds(911,1743),21))\r\n%%\r\nassert(isequal(number_of_folds(1245,3694),23))\r\n%%\r\nassert(isequal(number_of_folds(1721,740),21))\r\n%%\r\nassert(isequal(number_of_folds(3620,3919),24))\r\n%%\r\nassert(isequal(number_of_folds(1756,445),20))\r\n%%\r\nassert(isequal(number_of_folds(1033,1635),22))\r\n%%\r\nassert(isequal(number_of_folds(2380,1049),23))\r\n%%\r\nassert(isequal(number_of_folds(2412,2845),24))\r\n%%\r\nassert(isequal(number_of_folds(887,470),19))\r\n%%\r\nassert(isequal(number_of_folds(1187,1276),22))\r\n%%\r\nassert(isequal(number_of_folds(1697,2032),22))\r\n%%\r\nassert(isequal(number_of_folds(343,1050),20))\r\n%%\r\nassert(isequal(number_of_folds(3205,117),19))\r\n%%\r\nassert(isequal(number_of_folds(3716,2922),24))\r\n%%\r\nassert(isequal(number_of_folds(1955,2315),23))\r\n%%\r\nassert(isequal(number_of_folds(950,1836),21))\r\n%%\r\nassert(isequal(number_of_folds(3853,2188),24))\r\n%%\r\nassert(isequal(number_of_folds(2085,927),22))\r\n%%\r\nassert(isequal(number_of_folds(1956,2497),23))\r\n%%\r\nassert(isequal(number_of_folds(2717,1583),23))\r\n%%\r\nassert(isequal(number_of_folds(1470,3952),23))\r\n%%\r\nassert(isequal(number_of_folds(151,3541),20))\r\n%%\r\nassert(isequal(number_of_folds(3654,3185),24))\r\n%%\r\nassert(isequal(number_of_folds(395,1048),20))\r\n%%\r\nassert(isequal(number_of_folds(1342,2719),23))\r\n%%\r\nassert(isequal(number_of_folds(547,2885),22))\r\n%%\r\nassert(isequal(number_of_folds(428,2616),21))\r\n%%\r\nassert(isequal(number_of_folds(1977,3117),23))\r\n%%\r\nassert(isequal(number_of_folds(2861,3615),24))\r\n%%\r\nassert(isequal(number_of_folds(3564,1337),23))\r\n%%\r\nassert(isequal(number_of_folds(1,4000),13))\r\n%%\r\nassert(isequal(number_of_folds(2795,792),22))\r\n%%\r\nassert(isequal(number_of_folds(123,2977),19))\r\n%%\r\nassert(isequal(number_of_folds(2001,1920),22))\r\n%%\r\nassert(isequal(number_of_folds(3619,2440),24))\r\n%%\r\nassert(isequal(number_of_folds(2471,3438),24))\r\n%%\r\nassert(isequal(number_of_folds(3222,2307),24))\r\n%%\r\nassert(isequal(number_of_folds(732,960),20))\r\n%%\r\nassert(isequal(number_of_folds(3547,115),19))\r\n%%\r\nassert(isequal(number_of_folds(1960,672),21))\r\n%%\r\nassert(isequal(number_of_folds(3915,2851),24))\r\n%%\r\nassert(isequal(number_of_folds(2002,1885),22))\r\n%%\r\nassert(isequal(number_of_folds(239,2728),20))\r\n%%\r\nassert(isequal(number_of_folds(170,286),17))\r\n%%\r\nassert(isequal(number_of_folds(2087,387),21))\r\n%%\r\nassert(isequal(number_of_folds(3273,3271),24))\r\n%%\r\nassert(isequal(number_of_folds(2890,600),22))\r\n%%\r\nassert(isequal(number_of_folds(2639,2075),24))\r\n%%\r\nassert(isequal(number_of_folds(3892,2596),24))\r\n%%\r\nassert(isequal(number_of_folds(3202,1816),23))\r\n%%\r\nassert(isequal(number_of_folds(1730,3302),23))\r\n%%\r\nassert(isequal(number_of_folds(334,533),19))\r\n%%\r\nassert(isequal(number_of_folds(694,1564),21))\r\n%%\r\nassert(isequal(number_of_folds(3326,3214),24))\r\n%%\r\nassert(isequal(number_of_folds(242,1598),19))\r\n%%\r\nassert(isequal(number_of_folds(2108,1668),23))\r\n%%\r\nassert(isequal(number_of_folds(2628,2512),24))\r\n%%\r\nassert(isequal(number_of_folds(1168,1727),22))\r\n%%\r\nassert(isequal(number_of_folds(62,3937),18))\r\n%%\r\nassert(isequal(number_of_folds(669,425),19))\r\n%%\r\nassert(isequal(number_of_folds(1490,793),21))\r\n%%\r\nassert(isequal(number_of_folds(1959,1358),22))\r\n%%\r\nassert(isequal(number_of_folds(3807,3682),24))\r\n%%\r\nassert(isequal(number_of_folds(211,2952),20))\r\n%%\r\nassert(isequal(number_of_folds(1077,1692),22))\r\n%%\r\nassert(isequal(number_of_folds(2192,3771),24))\r\n%%\r\nassert(isequal(number_of_folds(1,1),2))\r\n%%\r\nassert(isequal(number_of_folds(1671,3933),23))\r\n%%\r\nassert(isequal(number_of_folds(1206,2805),23))\r\n%%\r\nassert(isequal(number_of_folds(2666,2157),24))\r\n%%\r\nassert(isequal(number_of_folds(2793,2667),24))\r\n%%\r\nassert(isequal(number_of_folds(713,513),20))\r\n%%\r\nassert(isequal(number_of_folds(3997,685),22))\r\n%%\r\nassert(isequal(number_of_folds(131,2245),20))\r\n%%\r\nassert(isequal(number_of_folds(3528,2677),24))\r\n%%\r\nassert(isequal(number_of_folds(762,1476),21))\r\n%%\r\nassert(isequal(number_of_folds(1843,3927),23))\r\n%%\r\nassert(isequal(number_of_folds(626,3423),22))\r\n%%\r\nassert(isequal(number_of_folds(2580,1506),23))\r\n%%\r\nassert(isequal(number_of_folds(764,1714),21))\r\n%%\r\nassert(isequal(number_of_folds(1929,483),20))\r\n%%\r\nassert(isequal(number_of_folds(2359,905),22))\r\n%%\r\nassert(isequal(number_of_folds(1539,2332),23))\r\n%%\r\nassert(isequal(number_of_folds(1008,1162),21))\r\n%%\r\nassert(isequal(number_of_folds(2469,1062),23))\r\n%%\r\nassert(isequal(number_of_folds(15,15),8))\r\n%%\r\nassert(isequal(number_of_folds(3298,3931),24))\r\n%%\r\nassert(isequal(number_of_folds(2921,1376),23))\r\n%%\r\nassert(isequal(number_of_folds(2337,432),21))\r\n%%\r\nassert(isequal(number_of_folds(3626,3519),24))\r\n%%\r\nassert(isequal(number_of_folds(3272,1043),23))\r\n%%\r\nassert(isequal(number_of_folds(3,2),4))\r\n%%\r\nassert(isequal(number_of_folds(2378,91),19))\r\n%%\r\nassert(isequal(number_of_folds(1702,1251),22))\r\n%%\r\nassert(isequal(number_of_folds(646,716),20))\r\n%%\r\nassert(isequal(number_of_folds(1692,377),20))\r\n%%\r\nassert(isequal(number_of_folds(16,15),9))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":115,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-26T22:22:34.000Z","updated_at":"2026-03-31T14:22:20.000Z","published_at":"2020-03-26T22:22:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFold\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the sheet in half so that the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elarger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e length between X and Y is halved and the other length remains the same.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRepeat step 2 until\u003c/w:t\u003e\u003c/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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e lengths X and Y 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eless\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e than 1 foot.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because\u003c/w:t\u003e\u003c/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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e sizes are now less than 1. This takes a total of 6 folds.\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":42634,"title":"Minimum of each diagonal","description":"The well-known \u003chttp://www.mathworks.com/help/matlab/ref/min.html min\u003e function can operate along either the rows or the columns of a matrix by using\r\n\r\n  [Y,I] = min(X,[],1) or [Y,I] = min(X,[],2)\r\n\r\nbut it cannot operate along a diagonal dimension. For this problem, create a function that returns the smallest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\r\n\r\n*Example*\r\n\r\nIf \r\n\r\n  X = magic(3) = [8 1 6\r\n                  3 5 7\r\n                  4 9 2]\r\n\r\nthen\r\n\r\n  Y = mindiag(X) = [4 3 2 1 6]\r\n\r\nSee also \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42635-maximum-of-each-diagonal maxdiag\u003e.","description_html":"\u003cp\u003eThe well-known \u003ca href = \"http://www.mathworks.com/help/matlab/ref/min.html\"\u003emin\u003c/a\u003e function can operate along either the rows or the columns of a matrix by using\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[Y,I] = min(X,[],1) or [Y,I] = min(X,[],2)\r\n\u003c/pre\u003e\u003cp\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the smallest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eX = magic(3) = [8 1 6\r\n                3 5 7\r\n                4 9 2]\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eY = mindiag(X) = [4 3 2 1 6]\r\n\u003c/pre\u003e\u003cp\u003eSee also \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42635-maximum-of-each-diagonal\"\u003emaxdiag\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = mindiag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isempty(mindiag([])))\r\n\r\n%%\r\nx = randi(100);\r\nassert(isequal(mindiag(x),x))\r\n\r\n%%\r\nx = randi(100,100,1);\r\nassert(isequal(mindiag(x),x(end:-1:1)'))\r\n\r\n%%\r\nx = randi(100,1,100);\r\nassert(isequal(mindiag(x),x))\r\n\r\n%%\r\nx = eye(2);\r\nassert(isequal(mindiag(x),[0 1 0]))\r\n\r\n%%\r\nx = magic(3);\r\nassert(isequal(mindiag(x),[4 3 2 1 6]))\r\n\r\n%%\r\nx = flipud(hankel(1:1000));\r\nassert(isequal(mindiag(x),[1:1000,zeros(1,1000-1)]))\r\n\r\n%%\r\nx = toeplitz(1:1000);\r\nassert(isequal(mindiag(x),[1000:-1:1,2:1000]))\r\n\r\n%%\r\nN = randi(1000);\r\nx = fliplr(toeplitz(1:N));\r\ny = ones(1,2*N-1);\r\ny(2:2:end) = 2;\r\nassert(isequal(mindiag(x),y))\r\n\r\n%%\r\nx = magic(10);\r\nx = x(:,1:3);\r\nassert(isequal(mindiag(x),[11 10 12 6 5 24 76 4 19 80 7 1]))\r\n\r\n%%\r\nx = hankel(-4:0,0:-2:-16);\r\nassert(isequal(mindiag(x),[0 -2 -4 -6 -8 -10 -12 -14 -16 -14 -12 -10 -8]))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":"2015-09-23T23:03:11.000Z","rescore_all_solutions":false,"group_id":24,"created_at":"2015-09-23T23:00:02.000Z","updated_at":"2026-04-01T07:12:19.000Z","published_at":"2015-09-23T23:00:02.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe well-known\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/min.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emin\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e function can operate along either the rows or the columns of a matrix by using\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[Y,I] = min(X,[],1) or [Y,I] = min(X,[],2)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the smallest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[X = magic(3) = [8 1 6\\n                3 5 7\\n                4 9 2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Y = mindiag(X) = [4 3 2 1 6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42635-maximum-of-each-diagonal\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emaxdiag\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"min\"","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:\"min\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"min\"","","\"","min","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74da0c30e0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74da0c3040\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74da0c25a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74da0c34a0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74da0c32c0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74da0c3220\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74da0c3180\u003e":"tag:\"min\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74da0c3180\u003e":"tag:\"min\""},"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:\"min\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"min\"","","\"","min","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74da0c30e0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74da0c3040\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74da0c25a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74da0c34a0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74da0c32c0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74da0c3220\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74da0c3180\u003e":"tag:\"min\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74da0c3180\u003e":"tag:\"min\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":42863,"difficulty_rating":"easy"},{"id":1838,"difficulty_rating":"easy"},{"id":49647,"difficulty_rating":"easy-medium"},{"id":45409,"difficulty_rating":"easy-medium"},{"id":45394,"difficulty_rating":"easy-medium"},{"id":42634,"difficulty_rating":"medium"}]}}