{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.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":"2026-04-06T00: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":45430,"title":"Juego de posiciones","description":"Crea una función que ordene vectores de tal manera que los primeros números sean negativos ordenados de menor a mayor. Y después vayan los números positivos ordenados de mayor a menor. \r\n\r\nPor ejemplo:\r\n\r\ny = [-1 6 15 -7 31 2 -4 -5];\r\n\r\ny_correct = [-7 -5 -4 -1 31 15 6 2];\r\n\r\nPD: Considerad el cero como número positivo. ","description_html":"\u003cp\u003eCrea una función que ordene vectores de tal manera que los primeros números sean negativos ordenados de menor a mayor. Y después vayan los números positivos ordenados de mayor a menor.\u003c/p\u003e\u003cp\u003ePor ejemplo:\u003c/p\u003e\u003cp\u003ey = [-1 6 15 -7 31 2 -4 -5];\u003c/p\u003e\u003cp\u003ey_correct = [-7 -5 -4 -1 31 15 6 2];\u003c/p\u003e\u003cp\u003ePD: Considerad el cero como número positivo.\u003c/p\u003e","function_template":"function x = order(y)\r\n \r\nend","test_suite":"%%\r\ny = [-1 6 15 -7 31 2 -4 -5];\r\ny_correct = [-7 -5 -4 -1 31 15 6 2];\r\nassert(isequal(order(y),y_correct))\r\n%%\r\ny=[6 7 -34 9 0];\r\ny_correct= [-34 9 7 6 0];\r\nassert(isequal(order(y),y_correct))\r\n%%\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":394942,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-09T11:48:17.000Z","updated_at":"2026-03-02T14:14:33.000Z","published_at":"2020-04-10T07:53:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCrea una función que ordene vectores de tal manera que los primeros números sean negativos ordenados de menor a mayor. Y después vayan los números positivos ordenados de mayor a menor.\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\u003ePor ejemplo:\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\u003ey = [-1 6 15 -7 31 2 -4 -5];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey_correct = [-7 -5 -4 -1 31 15 6 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\u003ePD: Considerad el cero como número positivo.\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":2189,"title":"Order of things - 1","description":"Let's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time. \r\n\r\nThe dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation. \r\n\r\n    A  B  C  D  E\r\n A  0  1  0  0  0\r\n B  0  0  0  0  0\r\n C  1  0  0  1  0\r\n D  1  0  0  0  0\r\n E  1  1  1  1  0\r\n\r\nA '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.\r\n\r\nIn matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.\r\n\r\n    B  A  D  C  E\r\n B  0  0  0  0  0\r\n A  1  0  0  0  0\r\n D  0  1  0  0  0\r\n C  0  1  1  0  0\r\n E  1  1  1  1  0\r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this example:\r\n\r\n [ 2 1 4 3 5 ]\r\n\r\nYou may assume that all calculations can be executed, in some order or another.","description_html":"\u003cp\u003eLet's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time.\u003c/p\u003e\u003cp\u003eThe dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation.\u003c/p\u003e\u003cpre\u003e    A  B  C  D  E\r\n A  0  1  0  0  0\r\n B  0  0  0  0  0\r\n C  1  0  0  1  0\r\n D  1  0  0  0  0\r\n E  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eA '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/p\u003e\u003cp\u003eIn matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.\u003c/p\u003e\u003cpre\u003e    B  A  D  C  E\r\n B  0  0  0  0  0\r\n A  1  0  0  0  0\r\n D  0  1  0  0  0\r\n C  0  1  1  0  0\r\n E  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this example:\u003c/p\u003e\u003cpre\u003e [ 2 1 4 3 5 ]\u003c/pre\u003e\u003cp\u003eYou may assume that all calculations can be executed, in some order or another.\u003c/p\u003e","function_template":"function order = calculation_order(dependencies)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"%%\r\ndependencies = [\r\n  0  0\r\n  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = [ 1 2 ];\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  0  0  0\r\n  0  0  0  0  0\r\n  1  0  0  1  0\r\n  1  0  0  0  0\r\n  1  1  1  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = [ 2 1 4 3 5 ];\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  1  1  1\r\n  0  0  1  1  1\r\n  0  0  0  1  1\r\n  0  0  0  0  1\r\n  0  0  0  0  0\r\n];\r\norder = calculation_order(dependencies);\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n\r\n%%\r\ndependencies_ = tril(randi(2,10)-1);\r\ndependencies_ = dependencies_-diag(diag(dependencies_));\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\nclear order_;\r\norder = calculation_order(dependencies);\r\n% [~,order] = sort(order_);\r\nassert(~nnz(triu(dependencies(order,order))));\r\n\r\n%%\r\ndependencies_ = randi(2,10)-1;\r\ndependencies_ = dependencies_-triu(dependencies_);\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\nclear order_; % to prevent the evalin hack\r\norder = calculation_order(dependencies);\r\n% [~,order] = sort(order_);\r\nassert(~nnz(triu(dependencies(order,order))));\r\n\r\n%%\r\n% n = 10;\r\n% dependencies_ = tril(randi(3,n)\u003e1|diag(ones(1,n-1),-1))\u0026~eye(n);\r\n% order_ = randperm(n);\r\n% dependencies = dependencies_(order_,order_);\r\ndependencies = [\r\n     0     1     1     0     1     0     0     0     0     1\r\n     0     0     0     0     1     0     0     0     0     1\r\n     0     1     0     0     1     0     0     0     0     1\r\n     1     0     1     0     1     1     0     0     0     0\r\n     0     0     0     0     0     0     0     0     0     0\r\n     0     0     0     0     0     0     0     1     0     1\r\n     1     1     1     0     0     0     0     1     1     1\r\n     1     1     0     0     1     0     0     0     0     1\r\n     1     1     1     1     0     1     0     1     0     1\r\n     0     0     0     0     1     0     0     0     0     0\r\n];\r\norder = calculation_order(dependencies);\r\n% [~,order_correct] = sort(order_);\r\norder_correct = [ 5    10     2     3     1     8     6     4     9     7 ];\r\nassert(isequal(order,order_correct));","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":"2014-02-18T08:49:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-17T16:26:27.000Z","updated_at":"2026-01-28T10:54:41.000Z","published_at":"2014-02-18T08:49:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation.\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  B  C  D  E\\n A  0  1  0  0  0\\n B  0  0  0  0  0\\n C  1  0  0  1  0\\n D  1  0  0  0  0\\n E  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.\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[    B  A  D  C  E\\n B  0  0  0  0  0\\n A  1  0  0  0  0\\n D  0  1  0  0  0\\n C  0  1  1  0  0\\n E  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this 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[ [ 2 1 4 3 5 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that all calculations can be executed, in some order or another.\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":2190,"title":"Order of things - 2","description":"This problem is closely related to \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1 Problem 2189, Order of things - 1\u003e. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other. \r\n\r\n* However, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.\r\n* Furthermore, if there are multiple orders possible, return them as multiple rows of the output vector.\r\n\r\nAgain, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. A |1| indicates that the calculation on that row depends on the one mentioned at the top of that column.\r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.\r\n\r\n   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  1  0\r\nD  1  0  1  0  0\r\nE  1  1  1  1  0\r\n\r\nThe above problem can not be solved, since |C| depends on |D|, which in its place depends on |C|. The returned value would be |[]| .\r\n\r\n   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  0  0\r\nD  1  0  0  0  0\r\nE  1  1  1  1  0\r\n\r\nThe returned matrix should be \r\n\r\n [\r\n   2 1 3 4 5 \r\n   2 1 4 3 5\r\n ]\r\n\r\nGood luck!","description_html":"\u003cp\u003eThis problem is closely related to \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\"\u003eProblem 2189, Order of things - 1\u003c/a\u003e. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/p\u003e\u003cul\u003e\u003cli\u003eHowever, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.\u003c/li\u003e\u003cli\u003eFurthermore, if there are multiple orders possible, return them as multiple rows of the output vector.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAgain, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. A \u003ctt\u003e1\u003c/tt\u003e indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/p\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  1  0\r\nD  1  0  1  0  0\r\nE  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eThe above problem can not be solved, since \u003ctt\u003eC\u003c/tt\u003e depends on \u003ctt\u003eD\u003c/tt\u003e, which in its place depends on \u003ctt\u003eC\u003c/tt\u003e. The returned value would be \u003ctt\u003e[]\u003c/tt\u003e .\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  0  0\r\nD  1  0  0  0  0\r\nE  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eThe returned matrix should be\u003c/p\u003e\u003cpre\u003e [\r\n   2 1 3 4 5 \r\n   2 1 4 3 5\r\n ]\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function order = calculation_order(dependencies)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"%%\r\ndependencies = [\r\n  0  0\r\n  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = [ 1 2 ];\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  0  0  0\r\n  0  0  0  0  0\r\n  1  0  0  0  0\r\n  1  0  0  0  0\r\n  1  1  1  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = sortrows([ 2 1 4 3 5 ; 2 1 3 4 5 ]);\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  0  0  0\r\n  1  0  0  0  0\r\n  1  0  0  0  0\r\n  1  0  0  0  0\r\n  1  1  1  1  0\r\n];\r\norder = calculation_order(dependencies);\r\nassert(isequal([],order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  1  1  1\r\n  0  0  1  1  1\r\n  0  0  0  1  1\r\n  0  0  0  0  1\r\n  0  0  0  0  0\r\n];\r\norder = calculation_order(dependencies);\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n\r\n%%\r\ndependencies_ = [\r\n  0  0  0  0  0\r\n  0  0  0  0  0\r\n  0  0  0  0  0\r\n  1  0  0  0  0\r\n  0  1  0  0  0\r\n];\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\norder_ = 0;\r\norder = calculation_order(dependencies);\r\nassert(isequal(size(unique(order,'rows'),1),30));\r\nfor ii = 1:size(order,1)\r\n   ordered = dependencies(order(ii,:),order(ii,:));\r\n   assert(~nnz(triu(ordered-diag(diag(ordered)))));\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":10,"test_suite_updated_at":"2014-02-19T08:24:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-18T08:49:38.000Z","updated_at":"2014-02-19T08:24:05.000Z","published_at":"2014-02-19T08:24:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is closely related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2189, Order of things - 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\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\u003eHowever, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.\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\u003eFurthermore, if there are multiple orders possible, return them as multiple rows of the output vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAgain, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.\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  B  C  D  E\\nA  0  1  0  0  0\\nB  0  0  0  0  0\\nC  1  0  0  1  0\\nD  1  0  1  0  0\\nE  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe above problem can not be solved, since\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e depends on\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eD\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which in its place depends on\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The returned value would be\u003c/w:t\u003e\u003c/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[]\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   A  B  C  D  E\\nA  0  1  0  0  0\\nB  0  0  0  0  0\\nC  1  0  0  0  0\\nD  1  0  0  0  0\\nE  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe returned matrix should 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[ [\\n   2 1 3 4 5 \\n   2 1 4 3 5\\n ]]]\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\u003eGood luck!\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":2191,"title":"Order of things - 3","description":"This problem is closely related to \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1 Problem 2189, Order of things - 1\u003e and \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2 Problem 2190, Order of things - 2\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other. \r\n\r\n* However, this time the tasks are grouped, and groups of tasks should be executed at once.\r\n* It may (still) be impossible to find a solution, since dependencies may be cyclic. But this may now also be due to the grouping of tasks. In any case, return an empty vector if no order is found.\r\n* There are still multiple orders possible, return them as multiple rows of the output vector.\r\n* The tasks within a group should of course be specified in the right order, when interdependent.\r\n\r\nThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency. \r\n\r\n   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  0  0  0\r\nC  0  1  0  0  0\r\nD  0  1  1  0  0\r\nE  1  0  0  0  0\r\n\r\nThe |1| on row |C|, column |B|, indicates that task |C| depends on task |B|. \r\n\r\nThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u003e 0, e.g.\r\n\r\n [ 1 1 2 3 3 ] \r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\r\n\r\n [ \r\n   1 2 3 4 5\r\n   1 2 3 5 4\r\n   2 1 3 4 5\r\n   2 1 3 5 4\r\n ]\r\n\r\nIf no order fulfilling the dependencies exists, return an empty vector.","description_html":"\u003cp\u003eThis problem is closely related to \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\"\u003eProblem 2189, Order of things - 1\u003c/a\u003e and \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\"\u003eProblem 2190, Order of things - 2\u003c/a\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/p\u003e\u003cul\u003e\u003cli\u003eHowever, this time the tasks are grouped, and groups of tasks should be executed at once.\u003c/li\u003e\u003cli\u003eIt may (still) be impossible to find a solution, since dependencies may be cyclic. But this may now also be due to the grouping of tasks. In any case, return an empty vector if no order is found.\u003c/li\u003e\u003cli\u003eThere are still multiple orders possible, return them as multiple rows of the output vector.\u003c/li\u003e\u003cli\u003eThe tasks within a group should of course be specified in the right order, when interdependent.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  0  0  0\r\nC  0  1  0  0  0\r\nD  0  1  1  0  0\r\nE  1  0  0  0  0\u003c/pre\u003e\u003cp\u003eThe \u003ctt\u003e1\u003c/tt\u003e on row \u003ctt\u003eC\u003c/tt\u003e, column \u003ctt\u003eB\u003c/tt\u003e, indicates that task \u003ctt\u003eC\u003c/tt\u003e depends on task \u003ctt\u003eB\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, e.g.\u003c/p\u003e\u003cpre\u003e [ 1 1 2 3 3 ] \u003c/pre\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\u003c/p\u003e\u003cpre\u003e [ \r\n   1 2 3 4 5\r\n   1 2 3 5 4\r\n   2 1 3 4 5\r\n   2 1 3 5 4\r\n ]\u003c/pre\u003e\u003cp\u003eIf no order fulfilling the dependencies exists, return an empty vector.\u003c/p\u003e","function_template":"function order = calculation_order(dependencies,groups)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"%%\r\ndependencies = [\r\n0  0  0  0  1\r\n0  0  1  1  0\r\n0  0  0  0  0\r\n0  0  1  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 3  3  1  2  1 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n5  3  4  2  1\r\n5  3  4  1  2\r\n4  3  5  2  1\r\n4  3  5  1  2\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  1  0  0  0\r\n0  0  1  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  1  0\r\n];\r\ngroups = [ 2  2  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n4  3  2  1  5\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  0  1\r\n0  0  1  0  0\r\n];\r\ngroups = [ 1  1  2  3  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n2  1  3  5  4\r\n4  3  1  5  2\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  0\r\n0  0  1  0  0\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 5  1  2  3  4 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  0\r\n1  0  0  0  0\r\n0  0  0  1  0\r\n0  1  0  0  0\r\n0  0  1  0  0\r\n];\r\ngroups = [ 1  1  2  3  2 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  1\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  0  0\r\n];\r\ngroups = [ 2  2  3  1  1 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies_ = ones(10+randi(10));\r\ndependencies_ = dependencies_-triu(dependencies_);\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\norder_ = 0;\r\norder = calculation_order(dependencies,1:size(dependencies_,1));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\norder = calculation_order(dependencies,ones(1,size(dependencies_,1)));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1,"test_suite_updated_at":"2014-02-21T15:59:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-18T08:50:55.000Z","updated_at":"2014-02-21T15:59:05.000Z","published_at":"2014-02-21T09:38: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\u003eThis problem is closely related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2189, Order of things - 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2190, Order of things - 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\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\u003eHowever, this time the tasks are grouped, and groups of tasks should be executed at once.\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\u003eIt may (still) be impossible to find a solution, since dependencies may be cyclic. But this may now also be due to the grouping of tasks. In any case, return an empty vector if no order is found.\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\u003eThere are still multiple orders possible, return them as multiple rows of the output vector.\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\u003eThe tasks within a group should of course be specified in the right order, when interdependent.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\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  B  C  D  E\\nA  0  0  0  0  0\\nB  0  0  0  0  0\\nC  0  1  0  0  0\\nD  0  1  1  0  0\\nE  1  0  0  0  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/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\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e on row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, indicates that task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e depends on task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, e.g.\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 1 2 3 3 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this 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[ [ \\n   1 2 3 4 5\\n   1 2 3 5 4\\n   2 1 3 4 5\\n   2 1 3 5 4\\n ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf no order fulfilling the dependencies exists, return an empty vector.\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":2192,"title":"Order of things - 4","description":"*This is the last assignment in the _Order of Things_-series. If that past incompleteness kept you from solving it, you may start now.* Open that bottle of wine, and spend an entertaining evening coding.\r\n\r\nThis problem is closely related to \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1 Problem 2189, Order of things - 1\u003e, \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2 Problem 2190, Order of things - 2\u003e, and \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2191-order-of-things-3 Problem 2191, Order of things - 3\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other. \r\n\r\nHowever, this is the most complex case, as \r\n* Calculations are preferably grouped, but may, due to their dependencies, not all be clustered. So groups of events may be split over different clusters. The number of clusters per group should be kept to a minimum. \r\n\r\nThe same complications as in problem 3 may apply:\r\n* It may (still) be impossible to find a solution, since dependencies may be cyclic. But this is now no longer due to the grouping of tasks, as you may, if necessary, break the rule of grouping. In any case, return an empty vector if no order is found.\r\n* There are still multiple orders possible, return them as multiple rows of the output vector.\r\n* The tasks within a group should of course be specified in the right order, when interdependent.\r\n\r\nThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency. \r\n\r\n   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  1  0  0\r\nC  1  0  0  0  0\r\nD  0  0  1  0  0\r\nE  1  0  0  0  0\r\n\r\nThe |1| on row |C|, column |B|, indicates that task |C| depends on task |B|. \r\n\r\nThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u003e 0, for every task, e.g. \r\n\r\n [ 1 1 2 2 3 ] \r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\r\n\r\n [ \r\n   1 3 4 2 5\r\n   1 3 4 5 2\r\n   1 5 3 4 2\r\n ]\r\n\r\nIf no order fulfilling the dependencies exists, return an empty vector.","description_html":"\u003cp\u003e\u003cb\u003eThis is the last assignment in the \u003ci\u003eOrder of Things\u003c/i\u003e-series. If that past incompleteness kept you from solving it, you may start now.\u003c/b\u003e Open that bottle of wine, and spend an entertaining evening coding.\u003c/p\u003e\u003cp\u003eThis problem is closely related to \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\"\u003eProblem 2189, Order of things - 1\u003c/a\u003e, \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\"\u003eProblem 2190, Order of things - 2\u003c/a\u003e, and \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2191-order-of-things-3\"\u003eProblem 2191, Order of things - 3\u003c/a\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/p\u003e\u003cp\u003eHowever, this is the most complex case, as \r\n* Calculations are preferably grouped, but may, due to their dependencies, not all be clustered. So groups of events may be split over different clusters. The number of clusters per group should be kept to a minimum.\u003c/p\u003e\u003cp\u003eThe same complications as in problem 3 may apply:\r\n* It may (still) be impossible to find a solution, since dependencies may be cyclic. But this is now no longer due to the grouping of tasks, as you may, if necessary, break the rule of grouping. In any case, return an empty vector if no order is found.\r\n* There are still multiple orders possible, return them as multiple rows of the output vector.\r\n* The tasks within a group should of course be specified in the right order, when interdependent.\u003c/p\u003e\u003cp\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  1  0  0\r\nC  1  0  0  0  0\r\nD  0  0  1  0  0\r\nE  1  0  0  0  0\u003c/pre\u003e\u003cp\u003eThe \u003ctt\u003e1\u003c/tt\u003e on row \u003ctt\u003eC\u003c/tt\u003e, column \u003ctt\u003eB\u003c/tt\u003e, indicates that task \u003ctt\u003eC\u003c/tt\u003e depends on task \u003ctt\u003eB\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, for every task, e.g.\u003c/p\u003e\u003cpre\u003e [ 1 1 2 2 3 ] \u003c/pre\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\u003c/p\u003e\u003cpre\u003e [ \r\n   1 3 4 2 5\r\n   1 3 4 5 2\r\n   1 5 3 4 2\r\n ]\u003c/pre\u003e\u003cp\u003eIf no order fulfilling the dependencies exists, return an empty vector.\u003c/p\u003e","function_template":"function order = calculation_order(dependencies,groups)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"dependencies = [\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  1\r\n0  0  0  0  1\r\n0  1  0  0  0\r\n];\r\ngroups = [ 3  1  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n3  2  5  4  1\r\n3  5  2  4  1\r\n5  4  2  3  1\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  1  0\r\n0  1  0  0  0\r\n0  0  0  1  0\r\n];\r\ngroups = [ 3  1  1  2  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n3  4  2  5  1\r\n3  4  5  2  1\r\n5  3  4  2  1\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  0  1  0  0\r\n0  0  0  1  0\r\n0  0  0  1  0\r\n0  0  0  0  0\r\n0  0  1  0  0\r\n];\r\ngroups = [ 1  3  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n2  1  4  5  3\r\n5  1  4  2  3\r\n4  1  3  2  5\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n    0 0 0 0 0\r\n    0 0 0 0 0\r\n    0 1 0 0 0\r\n    0 0 1 0 0\r\n    1 0 0 1 0\r\n    ];\r\ngroups = [1 2 2 2 2];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n    1 2 3 4 5\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  1  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 1  3  4  2  5 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n0  0  0  1  0\r\n0  0  1  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 1  3  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n1  2  4  5  3\r\n1  2  3  5  4\r\n1  5  4  2  3\r\n1  5  3  2  4\r\n1  4  3  2  5\r\n1  3  4  2  5\r\n5  4  3  2  1\r\n5  3  4  2  1\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies_ = ones(randi(10));\r\ndependencies_ = dependencies_-triu(dependencies_);\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\norder_ = 0;\r\norder = calculation_order(dependencies,1:size(dependencies_,1));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\norder = calculation_order(dependencies,ones(1,size(dependencies_,1)));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-18T08:57:21.000Z","updated_at":"2014-03-04T07:49:56.000Z","published_at":"2014-03-04T07:49: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThis is the last assignment in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOrder of Things\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e-series. If that past incompleteness kept you from solving it, you may start now.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Open that bottle of wine, and spend an entertaining evening coding.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is closely related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2189, Order of things - 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2190, Order of things - 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2191-order-of-things-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2191, Order of things - 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHowever, this is the most complex case, as * Calculations are preferably grouped, but may, due to their dependencies, not all be clustered. So groups of events may be split over different clusters. The number of clusters per group should be kept to a minimum.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe same complications as in problem 3 may apply: * It may (still) be impossible to find a solution, since dependencies may be cyclic. But this is now no longer due to the grouping of tasks, as you may, if necessary, break the rule of grouping. In any case, return an empty vector if no order is found. * There are still multiple orders possible, return them as multiple rows of the output vector. * The tasks within a group should of course be specified in the right order, when interdependent.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\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  B  C  D  E\\nA  0  0  0  0  0\\nB  0  0  1  0  0\\nC  1  0  0  0  0\\nD  0  0  1  0  0\\nE  1  0  0  0  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/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\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e on row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, indicates that task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e depends on task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, for every task, e.g.\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 1 2 2 3 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this 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[ [ \\n   1 3 4 2 5\\n   1 3 4 5 2\\n   1 5 3 4 2\\n ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf no order fulfilling the dependencies exists, return an empty vector.\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":45430,"title":"Juego de posiciones","description":"Crea una función que ordene vectores de tal manera que los primeros números sean negativos ordenados de menor a mayor. Y después vayan los números positivos ordenados de mayor a menor. \r\n\r\nPor ejemplo:\r\n\r\ny = [-1 6 15 -7 31 2 -4 -5];\r\n\r\ny_correct = [-7 -5 -4 -1 31 15 6 2];\r\n\r\nPD: Considerad el cero como número positivo. ","description_html":"\u003cp\u003eCrea una función que ordene vectores de tal manera que los primeros números sean negativos ordenados de menor a mayor. Y después vayan los números positivos ordenados de mayor a menor.\u003c/p\u003e\u003cp\u003ePor ejemplo:\u003c/p\u003e\u003cp\u003ey = [-1 6 15 -7 31 2 -4 -5];\u003c/p\u003e\u003cp\u003ey_correct = [-7 -5 -4 -1 31 15 6 2];\u003c/p\u003e\u003cp\u003ePD: Considerad el cero como número positivo.\u003c/p\u003e","function_template":"function x = order(y)\r\n \r\nend","test_suite":"%%\r\ny = [-1 6 15 -7 31 2 -4 -5];\r\ny_correct = [-7 -5 -4 -1 31 15 6 2];\r\nassert(isequal(order(y),y_correct))\r\n%%\r\ny=[6 7 -34 9 0];\r\ny_correct= [-34 9 7 6 0];\r\nassert(isequal(order(y),y_correct))\r\n%%\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":394942,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-09T11:48:17.000Z","updated_at":"2026-03-02T14:14:33.000Z","published_at":"2020-04-10T07:53:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCrea una función que ordene vectores de tal manera que los primeros números sean negativos ordenados de menor a mayor. Y después vayan los números positivos ordenados de mayor a menor.\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\u003ePor ejemplo:\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\u003ey = [-1 6 15 -7 31 2 -4 -5];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ey_correct = [-7 -5 -4 -1 31 15 6 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\u003ePD: Considerad el cero como número positivo.\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":2189,"title":"Order of things - 1","description":"Let's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time. \r\n\r\nThe dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation. \r\n\r\n    A  B  C  D  E\r\n A  0  1  0  0  0\r\n B  0  0  0  0  0\r\n C  1  0  0  1  0\r\n D  1  0  0  0  0\r\n E  1  1  1  1  0\r\n\r\nA '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.\r\n\r\nIn matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.\r\n\r\n    B  A  D  C  E\r\n B  0  0  0  0  0\r\n A  1  0  0  0  0\r\n D  0  1  0  0  0\r\n C  0  1  1  0  0\r\n E  1  1  1  1  0\r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this example:\r\n\r\n [ 2 1 4 3 5 ]\r\n\r\nYou may assume that all calculations can be executed, in some order or another.","description_html":"\u003cp\u003eLet's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time.\u003c/p\u003e\u003cp\u003eThe dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation.\u003c/p\u003e\u003cpre\u003e    A  B  C  D  E\r\n A  0  1  0  0  0\r\n B  0  0  0  0  0\r\n C  1  0  0  1  0\r\n D  1  0  0  0  0\r\n E  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eA '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/p\u003e\u003cp\u003eIn matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.\u003c/p\u003e\u003cpre\u003e    B  A  D  C  E\r\n B  0  0  0  0  0\r\n A  1  0  0  0  0\r\n D  0  1  0  0  0\r\n C  0  1  1  0  0\r\n E  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this example:\u003c/p\u003e\u003cpre\u003e [ 2 1 4 3 5 ]\u003c/pre\u003e\u003cp\u003eYou may assume that all calculations can be executed, in some order or another.\u003c/p\u003e","function_template":"function order = calculation_order(dependencies)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"%%\r\ndependencies = [\r\n  0  0\r\n  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = [ 1 2 ];\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  0  0  0\r\n  0  0  0  0  0\r\n  1  0  0  1  0\r\n  1  0  0  0  0\r\n  1  1  1  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = [ 2 1 4 3 5 ];\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  1  1  1\r\n  0  0  1  1  1\r\n  0  0  0  1  1\r\n  0  0  0  0  1\r\n  0  0  0  0  0\r\n];\r\norder = calculation_order(dependencies);\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n\r\n%%\r\ndependencies_ = tril(randi(2,10)-1);\r\ndependencies_ = dependencies_-diag(diag(dependencies_));\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\nclear order_;\r\norder = calculation_order(dependencies);\r\n% [~,order] = sort(order_);\r\nassert(~nnz(triu(dependencies(order,order))));\r\n\r\n%%\r\ndependencies_ = randi(2,10)-1;\r\ndependencies_ = dependencies_-triu(dependencies_);\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\nclear order_; % to prevent the evalin hack\r\norder = calculation_order(dependencies);\r\n% [~,order] = sort(order_);\r\nassert(~nnz(triu(dependencies(order,order))));\r\n\r\n%%\r\n% n = 10;\r\n% dependencies_ = tril(randi(3,n)\u003e1|diag(ones(1,n-1),-1))\u0026~eye(n);\r\n% order_ = randperm(n);\r\n% dependencies = dependencies_(order_,order_);\r\ndependencies = [\r\n     0     1     1     0     1     0     0     0     0     1\r\n     0     0     0     0     1     0     0     0     0     1\r\n     0     1     0     0     1     0     0     0     0     1\r\n     1     0     1     0     1     1     0     0     0     0\r\n     0     0     0     0     0     0     0     0     0     0\r\n     0     0     0     0     0     0     0     1     0     1\r\n     1     1     1     0     0     0     0     1     1     1\r\n     1     1     0     0     1     0     0     0     0     1\r\n     1     1     1     1     0     1     0     1     0     1\r\n     0     0     0     0     1     0     0     0     0     0\r\n];\r\norder = calculation_order(dependencies);\r\n% [~,order_correct] = sort(order_);\r\norder_correct = [ 5    10     2     3     1     8     6     4     9     7 ];\r\nassert(isequal(order,order_correct));","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":"2014-02-18T08:49:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-17T16:26:27.000Z","updated_at":"2026-01-28T10:54:41.000Z","published_at":"2014-02-18T08:49:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation.\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  B  C  D  E\\n A  0  1  0  0  0\\n B  0  0  0  0  0\\n C  1  0  0  1  0\\n D  1  0  0  0  0\\n E  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.\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[    B  A  D  C  E\\n B  0  0  0  0  0\\n A  1  0  0  0  0\\n D  0  1  0  0  0\\n C  0  1  1  0  0\\n E  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this 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[ [ 2 1 4 3 5 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that all calculations can be executed, in some order or another.\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":2190,"title":"Order of things - 2","description":"This problem is closely related to \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1 Problem 2189, Order of things - 1\u003e. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other. \r\n\r\n* However, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.\r\n* Furthermore, if there are multiple orders possible, return them as multiple rows of the output vector.\r\n\r\nAgain, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. A |1| indicates that the calculation on that row depends on the one mentioned at the top of that column.\r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.\r\n\r\n   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  1  0\r\nD  1  0  1  0  0\r\nE  1  1  1  1  0\r\n\r\nThe above problem can not be solved, since |C| depends on |D|, which in its place depends on |C|. The returned value would be |[]| .\r\n\r\n   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  0  0\r\nD  1  0  0  0  0\r\nE  1  1  1  1  0\r\n\r\nThe returned matrix should be \r\n\r\n [\r\n   2 1 3 4 5 \r\n   2 1 4 3 5\r\n ]\r\n\r\nGood luck!","description_html":"\u003cp\u003eThis problem is closely related to \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\"\u003eProblem 2189, Order of things - 1\u003c/a\u003e. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/p\u003e\u003cul\u003e\u003cli\u003eHowever, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.\u003c/li\u003e\u003cli\u003eFurthermore, if there are multiple orders possible, return them as multiple rows of the output vector.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAgain, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. A \u003ctt\u003e1\u003c/tt\u003e indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/p\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  1  0\r\nD  1  0  1  0  0\r\nE  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eThe above problem can not be solved, since \u003ctt\u003eC\u003c/tt\u003e depends on \u003ctt\u003eD\u003c/tt\u003e, which in its place depends on \u003ctt\u003eC\u003c/tt\u003e. The returned value would be \u003ctt\u003e[]\u003c/tt\u003e .\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  1  0  0  0\r\nB  0  0  0  0  0\r\nC  1  0  0  0  0\r\nD  1  0  0  0  0\r\nE  1  1  1  1  0\u003c/pre\u003e\u003cp\u003eThe returned matrix should be\u003c/p\u003e\u003cpre\u003e [\r\n   2 1 3 4 5 \r\n   2 1 4 3 5\r\n ]\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function order = calculation_order(dependencies)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"%%\r\ndependencies = [\r\n  0  0\r\n  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = [ 1 2 ];\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  0  0  0\r\n  0  0  0  0  0\r\n  1  0  0  0  0\r\n  1  0  0  0  0\r\n  1  1  1  1  0\r\n];\r\norder = calculation_order(dependencies);\r\norder_correct = sortrows([ 2 1 4 3 5 ; 2 1 3 4 5 ]);\r\nassert(isequal(order_correct,order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  0  0  0\r\n  1  0  0  0  0\r\n  1  0  0  0  0\r\n  1  0  0  0  0\r\n  1  1  1  1  0\r\n];\r\norder = calculation_order(dependencies);\r\nassert(isequal([],order));\r\n\r\n%%\r\ndependencies = [\r\n  0  1  1  1  1\r\n  0  0  1  1  1\r\n  0  0  0  1  1\r\n  0  0  0  0  1\r\n  0  0  0  0  0\r\n];\r\norder = calculation_order(dependencies);\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n\r\n%%\r\ndependencies_ = [\r\n  0  0  0  0  0\r\n  0  0  0  0  0\r\n  0  0  0  0  0\r\n  1  0  0  0  0\r\n  0  1  0  0  0\r\n];\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\norder_ = 0;\r\norder = calculation_order(dependencies);\r\nassert(isequal(size(unique(order,'rows'),1),30));\r\nfor ii = 1:size(order,1)\r\n   ordered = dependencies(order(ii,:),order(ii,:));\r\n   assert(~nnz(triu(ordered-diag(diag(ordered)))));\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":10,"test_suite_updated_at":"2014-02-19T08:24:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-18T08:49:38.000Z","updated_at":"2014-02-19T08:24:05.000Z","published_at":"2014-02-19T08:24:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is closely related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2189, Order of things - 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\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\u003eHowever, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.\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\u003eFurthermore, if there are multiple orders possible, return them as multiple rows of the output vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAgain, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e indicates that the calculation on that row depends on the one mentioned at the top of that column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.\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  B  C  D  E\\nA  0  1  0  0  0\\nB  0  0  0  0  0\\nC  1  0  0  1  0\\nD  1  0  1  0  0\\nE  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe above problem can not be solved, since\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e depends on\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eD\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which in its place depends on\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The returned value would be\u003c/w:t\u003e\u003c/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[]\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   A  B  C  D  E\\nA  0  1  0  0  0\\nB  0  0  0  0  0\\nC  1  0  0  0  0\\nD  1  0  0  0  0\\nE  1  1  1  1  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe returned matrix should 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[ [\\n   2 1 3 4 5 \\n   2 1 4 3 5\\n ]]]\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\u003eGood luck!\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":2191,"title":"Order of things - 3","description":"This problem is closely related to \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1 Problem 2189, Order of things - 1\u003e and \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2 Problem 2190, Order of things - 2\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other. \r\n\r\n* However, this time the tasks are grouped, and groups of tasks should be executed at once.\r\n* It may (still) be impossible to find a solution, since dependencies may be cyclic. But this may now also be due to the grouping of tasks. In any case, return an empty vector if no order is found.\r\n* There are still multiple orders possible, return them as multiple rows of the output vector.\r\n* The tasks within a group should of course be specified in the right order, when interdependent.\r\n\r\nThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency. \r\n\r\n   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  0  0  0\r\nC  0  1  0  0  0\r\nD  0  1  1  0  0\r\nE  1  0  0  0  0\r\n\r\nThe |1| on row |C|, column |B|, indicates that task |C| depends on task |B|. \r\n\r\nThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u003e 0, e.g.\r\n\r\n [ 1 1 2 3 3 ] \r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\r\n\r\n [ \r\n   1 2 3 4 5\r\n   1 2 3 5 4\r\n   2 1 3 4 5\r\n   2 1 3 5 4\r\n ]\r\n\r\nIf no order fulfilling the dependencies exists, return an empty vector.","description_html":"\u003cp\u003eThis problem is closely related to \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\"\u003eProblem 2189, Order of things - 1\u003c/a\u003e and \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\"\u003eProblem 2190, Order of things - 2\u003c/a\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/p\u003e\u003cul\u003e\u003cli\u003eHowever, this time the tasks are grouped, and groups of tasks should be executed at once.\u003c/li\u003e\u003cli\u003eIt may (still) be impossible to find a solution, since dependencies may be cyclic. But this may now also be due to the grouping of tasks. In any case, return an empty vector if no order is found.\u003c/li\u003e\u003cli\u003eThere are still multiple orders possible, return them as multiple rows of the output vector.\u003c/li\u003e\u003cli\u003eThe tasks within a group should of course be specified in the right order, when interdependent.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  0  0  0\r\nC  0  1  0  0  0\r\nD  0  1  1  0  0\r\nE  1  0  0  0  0\u003c/pre\u003e\u003cp\u003eThe \u003ctt\u003e1\u003c/tt\u003e on row \u003ctt\u003eC\u003c/tt\u003e, column \u003ctt\u003eB\u003c/tt\u003e, indicates that task \u003ctt\u003eC\u003c/tt\u003e depends on task \u003ctt\u003eB\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, e.g.\u003c/p\u003e\u003cpre\u003e [ 1 1 2 3 3 ] \u003c/pre\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\u003c/p\u003e\u003cpre\u003e [ \r\n   1 2 3 4 5\r\n   1 2 3 5 4\r\n   2 1 3 4 5\r\n   2 1 3 5 4\r\n ]\u003c/pre\u003e\u003cp\u003eIf no order fulfilling the dependencies exists, return an empty vector.\u003c/p\u003e","function_template":"function order = calculation_order(dependencies,groups)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"%%\r\ndependencies = [\r\n0  0  0  0  1\r\n0  0  1  1  0\r\n0  0  0  0  0\r\n0  0  1  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 3  3  1  2  1 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n5  3  4  2  1\r\n5  3  4  1  2\r\n4  3  5  2  1\r\n4  3  5  1  2\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  1  0  0  0\r\n0  0  1  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  1  0\r\n];\r\ngroups = [ 2  2  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n4  3  2  1  5\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  0  1\r\n0  0  1  0  0\r\n];\r\ngroups = [ 1  1  2  3  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n2  1  3  5  4\r\n4  3  1  5  2\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  0\r\n0  0  1  0  0\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 5  1  2  3  4 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  0\r\n1  0  0  0  0\r\n0  0  0  1  0\r\n0  1  0  0  0\r\n0  0  1  0  0\r\n];\r\ngroups = [ 1  1  2  3  2 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  1\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  0  0\r\n];\r\ngroups = [ 2  2  3  1  1 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies_ = ones(10+randi(10));\r\ndependencies_ = dependencies_-triu(dependencies_);\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\norder_ = 0;\r\norder = calculation_order(dependencies,1:size(dependencies_,1));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\norder = calculation_order(dependencies,ones(1,size(dependencies_,1)));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1,"test_suite_updated_at":"2014-02-21T15:59:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-18T08:50:55.000Z","updated_at":"2014-02-21T15:59:05.000Z","published_at":"2014-02-21T09:38: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\u003eThis problem is closely related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2189, Order of things - 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2190, Order of things - 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\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\u003eHowever, this time the tasks are grouped, and groups of tasks should be executed at once.\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\u003eIt may (still) be impossible to find a solution, since dependencies may be cyclic. But this may now also be due to the grouping of tasks. In any case, return an empty vector if no order is found.\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\u003eThere are still multiple orders possible, return them as multiple rows of the output vector.\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\u003eThe tasks within a group should of course be specified in the right order, when interdependent.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\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  B  C  D  E\\nA  0  0  0  0  0\\nB  0  0  0  0  0\\nC  0  1  0  0  0\\nD  0  1  1  0  0\\nE  1  0  0  0  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/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\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e on row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, indicates that task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e depends on task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, e.g.\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 1 2 3 3 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this 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[ [ \\n   1 2 3 4 5\\n   1 2 3 5 4\\n   2 1 3 4 5\\n   2 1 3 5 4\\n ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf no order fulfilling the dependencies exists, return an empty vector.\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":2192,"title":"Order of things - 4","description":"*This is the last assignment in the _Order of Things_-series. If that past incompleteness kept you from solving it, you may start now.* Open that bottle of wine, and spend an entertaining evening coding.\r\n\r\nThis problem is closely related to \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1 Problem 2189, Order of things - 1\u003e, \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2 Problem 2190, Order of things - 2\u003e, and \u003chttp://www.mathworks.nl/matlabcentral/cody/problems/2191-order-of-things-3 Problem 2191, Order of things - 3\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other. \r\n\r\nHowever, this is the most complex case, as \r\n* Calculations are preferably grouped, but may, due to their dependencies, not all be clustered. So groups of events may be split over different clusters. The number of clusters per group should be kept to a minimum. \r\n\r\nThe same complications as in problem 3 may apply:\r\n* It may (still) be impossible to find a solution, since dependencies may be cyclic. But this is now no longer due to the grouping of tasks, as you may, if necessary, break the rule of grouping. In any case, return an empty vector if no order is found.\r\n* There are still multiple orders possible, return them as multiple rows of the output vector.\r\n* The tasks within a group should of course be specified in the right order, when interdependent.\r\n\r\nThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency. \r\n\r\n   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  1  0  0\r\nC  1  0  0  0  0\r\nD  0  0  1  0  0\r\nE  1  0  0  0  0\r\n\r\nThe |1| on row |C|, column |B|, indicates that task |C| depends on task |B|. \r\n\r\nThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u003e 0, for every task, e.g. \r\n\r\n [ 1 1 2 2 3 ] \r\n\r\nReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\r\n\r\n [ \r\n   1 3 4 2 5\r\n   1 3 4 5 2\r\n   1 5 3 4 2\r\n ]\r\n\r\nIf no order fulfilling the dependencies exists, return an empty vector.","description_html":"\u003cp\u003e\u003cb\u003eThis is the last assignment in the \u003ci\u003eOrder of Things\u003c/i\u003e-series. If that past incompleteness kept you from solving it, you may start now.\u003c/b\u003e Open that bottle of wine, and spend an entertaining evening coding.\u003c/p\u003e\u003cp\u003eThis problem is closely related to \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\"\u003eProblem 2189, Order of things - 1\u003c/a\u003e, \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\"\u003eProblem 2190, Order of things - 2\u003c/a\u003e, and \u003ca href = \"http://www.mathworks.nl/matlabcentral/cody/problems/2191-order-of-things-3\"\u003eProblem 2191, Order of things - 3\u003c/a\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/p\u003e\u003cp\u003eHowever, this is the most complex case, as \r\n* Calculations are preferably grouped, but may, due to their dependencies, not all be clustered. So groups of events may be split over different clusters. The number of clusters per group should be kept to a minimum.\u003c/p\u003e\u003cp\u003eThe same complications as in problem 3 may apply:\r\n* It may (still) be impossible to find a solution, since dependencies may be cyclic. But this is now no longer due to the grouping of tasks, as you may, if necessary, break the rule of grouping. In any case, return an empty vector if no order is found.\r\n* There are still multiple orders possible, return them as multiple rows of the output vector.\r\n* The tasks within a group should of course be specified in the right order, when interdependent.\u003c/p\u003e\u003cp\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\u003c/p\u003e\u003cpre\u003e   A  B  C  D  E\r\nA  0  0  0  0  0\r\nB  0  0  1  0  0\r\nC  1  0  0  0  0\r\nD  0  0  1  0  0\r\nE  1  0  0  0  0\u003c/pre\u003e\u003cp\u003eThe \u003ctt\u003e1\u003c/tt\u003e on row \u003ctt\u003eC\u003c/tt\u003e, column \u003ctt\u003eB\u003c/tt\u003e, indicates that task \u003ctt\u003eC\u003c/tt\u003e depends on task \u003ctt\u003eB\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, for every task, e.g.\u003c/p\u003e\u003cpre\u003e [ 1 1 2 2 3 ] \u003c/pre\u003e\u003cp\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this example:\u003c/p\u003e\u003cpre\u003e [ \r\n   1 3 4 2 5\r\n   1 3 4 5 2\r\n   1 5 3 4 2\r\n ]\u003c/pre\u003e\u003cp\u003eIf no order fulfilling the dependencies exists, return an empty vector.\u003c/p\u003e","function_template":"function order = calculation_order(dependencies,groups)\r\n  order  = 1:size(dependencies,1);\r\nend","test_suite":"dependencies = [\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  0  1\r\n0  0  0  0  1\r\n0  1  0  0  0\r\n];\r\ngroups = [ 3  1  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n3  2  5  4  1\r\n3  5  2  4  1\r\n5  4  2  3  1\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  1  0  0  0\r\n0  0  0  0  0\r\n0  0  0  1  0\r\n0  1  0  0  0\r\n0  0  0  1  0\r\n];\r\ngroups = [ 3  1  1  2  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n3  4  2  5  1\r\n3  4  5  2  1\r\n5  3  4  2  1\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  0  1  0  0\r\n0  0  0  1  0\r\n0  0  0  1  0\r\n0  0  0  0  0\r\n0  0  1  0  0\r\n];\r\ngroups = [ 1  3  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n2  1  4  5  3\r\n5  1  4  2  3\r\n4  1  3  2  5\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n    0 0 0 0 0\r\n    0 0 0 0 0\r\n    0 1 0 0 0\r\n    0 0 1 0 0\r\n    1 0 0 1 0\r\n    ];\r\ngroups = [1 2 2 2 2];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n    1 2 3 4 5\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  1  0\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n1  0  0  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 1  3  4  2  5 ];\r\norder = calculation_order(dependencies,groups);\r\nassert(isempty(order));\r\n\r\n%%\r\ndependencies = [\r\n0  0  0  0  0\r\n0  0  0  0  0\r\n0  0  0  1  0\r\n0  0  1  0  0\r\n0  0  0  0  0\r\n];\r\ngroups = [ 1  3  2  1  2 ];\r\norder = calculation_order(dependencies,groups);\r\norder_correct = [\r\n1  2  4  5  3\r\n1  2  3  5  4\r\n1  5  4  2  3\r\n1  5  3  2  4\r\n1  4  3  2  5\r\n1  3  4  2  5\r\n5  4  3  2  1\r\n5  3  4  2  1\r\n];\r\nassert(isequal(sortrows(order_correct),sortrows(order)));\r\n\r\n%%\r\ndependencies_ = ones(randi(10));\r\ndependencies_ = dependencies_-triu(dependencies_);\r\norder_ = randperm(size(dependencies_,1));\r\ndependencies = dependencies_(order_,order_);\r\norder_ = 0;\r\norder = calculation_order(dependencies,1:size(dependencies_,1));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\norder = calculation_order(dependencies,ones(1,size(dependencies_,1)));\r\nordered = dependencies(order,order);\r\nassert(~nnz(triu(ordered-diag(diag(ordered)))));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":6556,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-02-18T08:57:21.000Z","updated_at":"2014-03-04T07:49:56.000Z","published_at":"2014-03-04T07:49: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThis is the last assignment in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOrder of Things\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e-series. If that past incompleteness kept you from solving it, you may start now.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Open that bottle of wine, and spend an entertaining evening coding.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is closely related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2189-order-of-things-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2189, Order of things - 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2190-order-of-things-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2190, Order of things - 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.nl/matlabcentral/cody/problems/2191-order-of-things-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2191, Order of things - 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. For the details, see the description for those problems. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHowever, this is the most complex case, as * Calculations are preferably grouped, but may, due to their dependencies, not all be clustered. So groups of events may be split over different clusters. The number of clusters per group should be kept to a minimum.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe same complications as in problem 3 may apply: * It may (still) be impossible to find a solution, since dependencies may be cyclic. But this is now no longer due to the grouping of tasks, as you may, if necessary, break the rule of grouping. In any case, return an empty vector if no order is found. * There are still multiple orders possible, return them as multiple rows of the output vector. * The tasks within a group should of course be specified in the right order, when interdependent.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dependencies of the tasks on each other is expressed in a matrix, where each row corresponds to the execution of a task, and each column to the dependency.\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  B  C  D  E\\nA  0  0  0  0  0\\nB  0  0  1  0  0\\nC  1  0  0  0  0\\nD  0  0  1  0  0\\nE  1  0  0  0  0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/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\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e on row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, indicates that task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e depends on task\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe grouping of tasks is expressed as an input vector with groups assigned an integer value \u0026gt; 0, for every task, e.g.\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 1 2 2 3 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. If multiple orders exist, return them all as rows of a matrix. In this 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[ [ \\n   1 3 4 2 5\\n   1 3 4 5 2\\n   1 5 3 4 2\\n ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf no order fulfilling the dependencies exists, return an empty vector.\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:\"order\"","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:\"order\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"order\"","","\"","order","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f17bfdd8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f69f17bfd38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f17bf478\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f17800c0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f1780020\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f17bff18\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f17bfe78\u003e":"tag:\"order\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f17bfe78\u003e":"tag:\"order\""},"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":"cody-search","password":"78X075ddcV44","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:\"order\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"order\"","","\"","order","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f17bfdd8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f69f17bfd38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f17bf478\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f17800c0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f1780020\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f17bff18\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f17bfe78\u003e":"tag:\"order\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f17bfe78\u003e":"tag:\"order\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":45430,"difficulty_rating":"easy"},{"id":2189,"difficulty_rating":"easy-medium"},{"id":2190,"difficulty_rating":"medium"},{"id":2191,"difficulty_rating":"unrated"},{"id":2192,"difficulty_rating":"unrated"}]}}