{"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":45394,"title":"Count the number of folds needed to pack a large sheet","description":"In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\r\n\r\n# Lay down a large sheet of paper of size X-by-Y feet.\r\n# _Fold_ the sheet in half so that the _larger_ length between X and Y is halved and the other length remains the same.\r\n# Repeat step 2 until _both_ lengths X and Y are _less_ than 1 foot.\r\n\r\nFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u003c= X \u003c= 4000 and 1 \u003c= Y \u003c= 4000. \r\n\r\nAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u003e (4,2.5) -\u003e (2,2.5) -\u003e (2,1.25) -\u003e (1,1.25) -\u003e (1,0.625) -\u003e (0.5,0.625). We stop because _both_ sizes are now less than 1. This takes a total of 6 folds.","description_html":"\u003cp\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/p\u003e\u003col\u003e\u003cli\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/li\u003e\u003cli\u003e\u003ci\u003eFold\u003c/i\u003e the sheet in half so that the \u003ci\u003elarger\u003c/i\u003e length between X and Y is halved and the other length remains the same.\u003c/li\u003e\u003cli\u003eRepeat step 2 until \u003ci\u003eboth\u003c/i\u003e lengths X and Y are \u003ci\u003eless\u003c/i\u003e than 1 foot.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/p\u003e\u003cp\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because \u003ci\u003eboth\u003c/i\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/p\u003e","function_template":"function y = number_of_folds(X,Y)\r\n  y = X;\r\nend","test_suite":"%%\r\nassert(isequal(number_of_folds(3247,2132),24))\r\n%%\r\nassert(isequal(number_of_folds(1403,3757),23))\r\n%%\r\nassert(isequal(number_of_folds(3504,2201),24))\r\n%%\r\nassert(isequal(number_of_folds(2490,2349),24))\r\n%%\r\nassert(isequal(number_of_folds(831,1205),21))\r\n%%\r\nassert(isequal(number_of_folds(1884,922),21))\r\n%%\r\nassert(isequal(number_of_folds(2,4),5))\r\n%%\r\nassert(isequal(number_of_folds(3378,780),22))\r\n%%\r\nassert(isequal(number_of_folds(904,683),20))\r\n%%\r\nassert(isequal(number_of_folds(911,1743),21))\r\n%%\r\nassert(isequal(number_of_folds(1245,3694),23))\r\n%%\r\nassert(isequal(number_of_folds(1721,740),21))\r\n%%\r\nassert(isequal(number_of_folds(3620,3919),24))\r\n%%\r\nassert(isequal(number_of_folds(1756,445),20))\r\n%%\r\nassert(isequal(number_of_folds(1033,1635),22))\r\n%%\r\nassert(isequal(number_of_folds(2380,1049),23))\r\n%%\r\nassert(isequal(number_of_folds(2412,2845),24))\r\n%%\r\nassert(isequal(number_of_folds(887,470),19))\r\n%%\r\nassert(isequal(number_of_folds(1187,1276),22))\r\n%%\r\nassert(isequal(number_of_folds(1697,2032),22))\r\n%%\r\nassert(isequal(number_of_folds(343,1050),20))\r\n%%\r\nassert(isequal(number_of_folds(3205,117),19))\r\n%%\r\nassert(isequal(number_of_folds(3716,2922),24))\r\n%%\r\nassert(isequal(number_of_folds(1955,2315),23))\r\n%%\r\nassert(isequal(number_of_folds(950,1836),21))\r\n%%\r\nassert(isequal(number_of_folds(3853,2188),24))\r\n%%\r\nassert(isequal(number_of_folds(2085,927),22))\r\n%%\r\nassert(isequal(number_of_folds(1956,2497),23))\r\n%%\r\nassert(isequal(number_of_folds(2717,1583),23))\r\n%%\r\nassert(isequal(number_of_folds(1470,3952),23))\r\n%%\r\nassert(isequal(number_of_folds(151,3541),20))\r\n%%\r\nassert(isequal(number_of_folds(3654,3185),24))\r\n%%\r\nassert(isequal(number_of_folds(395,1048),20))\r\n%%\r\nassert(isequal(number_of_folds(1342,2719),23))\r\n%%\r\nassert(isequal(number_of_folds(547,2885),22))\r\n%%\r\nassert(isequal(number_of_folds(428,2616),21))\r\n%%\r\nassert(isequal(number_of_folds(1977,3117),23))\r\n%%\r\nassert(isequal(number_of_folds(2861,3615),24))\r\n%%\r\nassert(isequal(number_of_folds(3564,1337),23))\r\n%%\r\nassert(isequal(number_of_folds(1,4000),13))\r\n%%\r\nassert(isequal(number_of_folds(2795,792),22))\r\n%%\r\nassert(isequal(number_of_folds(123,2977),19))\r\n%%\r\nassert(isequal(number_of_folds(2001,1920),22))\r\n%%\r\nassert(isequal(number_of_folds(3619,2440),24))\r\n%%\r\nassert(isequal(number_of_folds(2471,3438),24))\r\n%%\r\nassert(isequal(number_of_folds(3222,2307),24))\r\n%%\r\nassert(isequal(number_of_folds(732,960),20))\r\n%%\r\nassert(isequal(number_of_folds(3547,115),19))\r\n%%\r\nassert(isequal(number_of_folds(1960,672),21))\r\n%%\r\nassert(isequal(number_of_folds(3915,2851),24))\r\n%%\r\nassert(isequal(number_of_folds(2002,1885),22))\r\n%%\r\nassert(isequal(number_of_folds(239,2728),20))\r\n%%\r\nassert(isequal(number_of_folds(170,286),17))\r\n%%\r\nassert(isequal(number_of_folds(2087,387),21))\r\n%%\r\nassert(isequal(number_of_folds(3273,3271),24))\r\n%%\r\nassert(isequal(number_of_folds(2890,600),22))\r\n%%\r\nassert(isequal(number_of_folds(2639,2075),24))\r\n%%\r\nassert(isequal(number_of_folds(3892,2596),24))\r\n%%\r\nassert(isequal(number_of_folds(3202,1816),23))\r\n%%\r\nassert(isequal(number_of_folds(1730,3302),23))\r\n%%\r\nassert(isequal(number_of_folds(334,533),19))\r\n%%\r\nassert(isequal(number_of_folds(694,1564),21))\r\n%%\r\nassert(isequal(number_of_folds(3326,3214),24))\r\n%%\r\nassert(isequal(number_of_folds(242,1598),19))\r\n%%\r\nassert(isequal(number_of_folds(2108,1668),23))\r\n%%\r\nassert(isequal(number_of_folds(2628,2512),24))\r\n%%\r\nassert(isequal(number_of_folds(1168,1727),22))\r\n%%\r\nassert(isequal(number_of_folds(62,3937),18))\r\n%%\r\nassert(isequal(number_of_folds(669,425),19))\r\n%%\r\nassert(isequal(number_of_folds(1490,793),21))\r\n%%\r\nassert(isequal(number_of_folds(1959,1358),22))\r\n%%\r\nassert(isequal(number_of_folds(3807,3682),24))\r\n%%\r\nassert(isequal(number_of_folds(211,2952),20))\r\n%%\r\nassert(isequal(number_of_folds(1077,1692),22))\r\n%%\r\nassert(isequal(number_of_folds(2192,3771),24))\r\n%%\r\nassert(isequal(number_of_folds(1,1),2))\r\n%%\r\nassert(isequal(number_of_folds(1671,3933),23))\r\n%%\r\nassert(isequal(number_of_folds(1206,2805),23))\r\n%%\r\nassert(isequal(number_of_folds(2666,2157),24))\r\n%%\r\nassert(isequal(number_of_folds(2793,2667),24))\r\n%%\r\nassert(isequal(number_of_folds(713,513),20))\r\n%%\r\nassert(isequal(number_of_folds(3997,685),22))\r\n%%\r\nassert(isequal(number_of_folds(131,2245),20))\r\n%%\r\nassert(isequal(number_of_folds(3528,2677),24))\r\n%%\r\nassert(isequal(number_of_folds(762,1476),21))\r\n%%\r\nassert(isequal(number_of_folds(1843,3927),23))\r\n%%\r\nassert(isequal(number_of_folds(626,3423),22))\r\n%%\r\nassert(isequal(number_of_folds(2580,1506),23))\r\n%%\r\nassert(isequal(number_of_folds(764,1714),21))\r\n%%\r\nassert(isequal(number_of_folds(1929,483),20))\r\n%%\r\nassert(isequal(number_of_folds(2359,905),22))\r\n%%\r\nassert(isequal(number_of_folds(1539,2332),23))\r\n%%\r\nassert(isequal(number_of_folds(1008,1162),21))\r\n%%\r\nassert(isequal(number_of_folds(2469,1062),23))\r\n%%\r\nassert(isequal(number_of_folds(15,15),8))\r\n%%\r\nassert(isequal(number_of_folds(3298,3931),24))\r\n%%\r\nassert(isequal(number_of_folds(2921,1376),23))\r\n%%\r\nassert(isequal(number_of_folds(2337,432),21))\r\n%%\r\nassert(isequal(number_of_folds(3626,3519),24))\r\n%%\r\nassert(isequal(number_of_folds(3272,1043),23))\r\n%%\r\nassert(isequal(number_of_folds(3,2),4))\r\n%%\r\nassert(isequal(number_of_folds(2378,91),19))\r\n%%\r\nassert(isequal(number_of_folds(1702,1251),22))\r\n%%\r\nassert(isequal(number_of_folds(646,716),20))\r\n%%\r\nassert(isequal(number_of_folds(1692,377),20))\r\n%%\r\nassert(isequal(number_of_folds(16,15),9))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":115,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-26T22:22:34.000Z","updated_at":"2026-03-31T14:22:20.000Z","published_at":"2020-03-26T22:22:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFold\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the sheet in half so that the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elarger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e length between X and Y is halved and the other length remains the same.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRepeat step 2 until\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e lengths X and Y are\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eless\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e than 1 foot.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44901,"title":"Rearrange the given matrix to have all its zeros climb up to the top of each column - using for loops.","description":"Given a matrix x, *using loops only* return a matrix y, in which all the zeros have \"climbed\" up to the top. That is, any zeros in each column should be moved to the top without disturbing The order of the remaining nonzero numbers in the column.","description_html":"\u003cp\u003eGiven a matrix x, \u003cb\u003eusing loops only\u003c/b\u003e return a matrix y, in which all the zeros have \"climbed\" up to the top. That is, any zeros in each column should be moved to the top without disturbing The order of the remaining nonzero numbers in the column.\u003c/p\u003e","function_template":"function y = zerosFirst(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [0     0     1     1\r\n     0     1    -1    -1\r\n     2     1    -1     2\r\n     2     2     0     0\r\n    -1     0     2     1\r\n     0     1     0     1];\r\n \r\ny_correct = [0     0     0     0\r\n             0     0     0     1\r\n             0     1     1    -1\r\n             2     1    -1     2\r\n             2     2    -1     1\r\n            -1     1     2     1];\r\n        \r\nassert(isequal(zerosFirst(x),y_correct))\r\n\r\n%%\r\nx = [12 56 0 0 65 122 0 37]'\r\n\r\ny_correct = [0     0     0    12    56    65   122    37]'\r\n        \r\nassert(isequal(zerosFirst(x),y_correct))\r\n\r\n%%\r\nfiletext = fileread('zerosFirst.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\t\r\n%%\r\nfiletext = fileread('zerosFirst.m');\r\nassert(~isempty(strfind(filetext, 'for')),'must use a for loop in solving this problem')\r\n%%\r\nfiletext = fileread('zerosFirst.m');\r\nassert(isempty(strfind(filetext, '!echo')),'!echo hacks are forbidden')\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":278101,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-05-19T11:15:18.000Z","updated_at":"2025-11-29T16:22:51.000Z","published_at":"2019-05-19T11:15:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eusing loops only\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e return a matrix y, in which all the zeros have \\\"climbed\\\" up to the top. That is, any zeros in each column should be moved to the top without disturbing The order of the remaining nonzero numbers in the column.\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":60791,"title":"Sum of Even Fibonacci Numbers","description":"Description:\r\nThe Fibonacci sequence is defined as follows:F(1)=1,F(2)=1,F(n)=F(n−1)+F(n−2) for n\u003e2\r\nWrite a function that computes the sum of all even Fibonacci numbers that do not exceed a given number NNN.\r\nExample:\r\nFor N=10, the Fibonacci sequence up to 10 is:\r\n1,1,2,3,5,8\r\nThe even numbers are 2 and 8, and their sum is 10.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 201px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 100.5px; transform-origin: 407px 100.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eDescription:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Fibonacci sequence is defined as follows:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e−\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e+\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e−\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e for \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u0026gt;\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that computes the sum of \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eall even Fibonacci numbers\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e that do not exceed a given number \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e10, the Fibonacci sequence up to 10 is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e5\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e8\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe even numbers are \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e2 and 8\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and their sum is \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e10\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function sum_even_fib = even_fibonacci_sum(N)\r\n    % Write your code here\r\nend\r\n","test_suite":"%% Test 1: Basic Case\r\nx = 10;\r\ny_correct = 10; % (2 + 8)\r\nassert(isequal(even_fibonacci_sum(x), y_correct))\r\n\r\n%% Test 2: Larger N\r\nx = 34;\r\ny_correct = 44; % (2 + 8 + 34)\r\nassert(isequal(even_fibonacci_sum(x), y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":383919,"edited_by":383919,"edited_at":"2025-02-10T11:48:53.000Z","deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-02-10T11:47:18.000Z","updated_at":"2025-11-14T09:05:50.000Z","published_at":"2025-02-10T11:48:53.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Fibonacci sequence is defined as follows:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e−\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e+\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e−\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that computes the sum of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall even Fibonacci numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that do not exceed a given number \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e10, the Fibonacci sequence up to 10 is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe even numbers are \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2 and 8\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and their sum is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e10\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44454,"title":"How many Integers?","description":"Count the integers in a given vector |v|.\r\n\r\nYou *must* use a loop to count each element separately.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\n  Output: n = 6    (9.0 is also an integer)\r\n\r\n  Input:  v = [1.2, 2.3, 4.5]\r\n  Output: n = 0","description_html":"\u003cp\u003eCount the integers in a given vector \u003ctt\u003ev\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eYou \u003cb\u003emust\u003c/b\u003e use a loop to count each element separately.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nOutput: n = 6    (9.0 is also an integer)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.2, 2.3, 4.5]\r\nOutput: n = 0\r\n\u003c/pre\u003e","function_template":"function n = integerCount(v)\r\n    % write your code instead of this line\r\n    n = length(v);\r\n    % \r\nend","test_suite":"%%\r\nfiletext = fileread('integerCount.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nn_correct = 6;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = [1.6, 5.7, 4.8, -3.5, 5.3, 9.2, -1.1, 0.01, 1.2]\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = []\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":464,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:23:07.000Z","updated_at":"2026-02-11T15:35:06.000Z","published_at":"2017-12-16T22:23:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCount the integers in a given vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emust\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use a loop to count each element separately.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\\nOutput: n = 6    (9.0 is also an integer)\\n\\nInput:  v = [1.2, 2.3, 4.5]\\nOutput: n = 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":59721,"title":"finding vector pair with min angle between them","description":"given a matrix with more than one row , compare row vectors of the given matrix and find the pair with the minumum angle between them , \"without using the dot fucntion\" \r\nyou can find the angle from the following formula\r\n θ = cos-1 [ (a. b) / (|a| |b|) ]\r\nthe product between the two vectors is the dot product \r\na⋅b=∑(ai​)*(bi)   from i=1 to n​\r\nthe length of a vector is the square root of the sum of the squares of the components\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.440001px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 222px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 111px; transform-origin: 407px 111px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003egiven a matrix with more than one row , compare row vectors of the given matrix and find the pair with the minumum angle between them , \"without using the dot fucntion\" \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eyou can find the angle from the following formula\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e θ = cos-1 [ (a. b) / (|a| |b|) ]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ethe product between the two vectors is the dot product \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ea\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e⋅\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eb\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e∑(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ea\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ei\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e​)*(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eb\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ei)   from i=1 to n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e​\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ethe length of a vector is the square root of the sum of the squares of the components\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [v1 v2] = minAngle(mat)\r\n   \r\nend","test_suite":"%%\r\nmat = [ 155    12   344   356\r\n   305   234   135    40\r\n   227    13   316   310\r\n   266    72    51   178\r\n     8   195   166   289];\r\nres1=[155    12   344   356];\r\nres2=[227    13   316   310];\r\n[v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n\r\n%%\r\nmat=[  2    50    47\r\n    24    99    24\r\n    89    23    42\r\n    13    37     9\r\n    66     5    83\r\n     2     5    95\r\n    60    28     3\r\n    52    84    13\r\n    87    35    14\r\n    37    93    17\r\n    80    43   100\r\n    20    16    98\r\n    27    41     3\r\n    59    86    76\r\n    22    56    26\r\n    99    68    42\r\n    13    94    40];\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n res1=[   13    37     9];\r\n  res2=[  37    93    17];\r\n [v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n\r\n%%\r\nmat=[ 79     4    66    79    23\r\n    22    42    94     3    25\r\n    78    36    58    16    71\r\n    55    52    23    23     8\r\n    67     3     4    80    82\r\n    96    74    85    74    98];\r\n\r\n   res1=[ 78    36    58    16    71];\r\n\r\n\r\n\r\n   res2=[ 96    74    85    74    98];\r\n    [v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n\r\n %%\r\n  mat=[ 8    47    50    69\r\n    78    49    11    83\r\n    68    53    63    98\r\n    97    74   100    57\r\n     4    48    24    91\r\n    96    46    12    92\r\n    64    61     4     1\r\n    73    61    72    71\r\n    78     6    47    63\r\n    52    34    18    41\r\n    46     3    95    38\r\n   100    10    52     2\r\n    88    71    59    25\r\n    63    33    99    43\r\n    95    56    48    44\r\n    73     6    13    14\r\n    56    60     8    84\r\n    96    60     7    85\r\n     8    90    54    76\r\n     1     6    39    70\r\n    83    12    18    44\r\n    44     9    85    11\r\n    65    43    17    90\r\n    44    68    36    34\r\n    92    89    46    89\r\n    36    37    65    79\r\n    11    69    76    41\r\n    41    17    23    56\r\n    94    10    16     7\r\n    51    98    17    70\r\n    94    18    53    11\r\n    45     9    38    42\r\n    59    99    32    31\r\n    81    85    12    82\r\n    46    48    87   100\r\n    52    17    78    17\r\n    35    55    61    57\r\n    46    55    22    93\r\n    52    51    31    10\r\n    84    56    31    34\r\n    77    51    62    66\r\n    41    88    17    40\r\n    90    62    86    20\r\n    86    50    60    48\r\n    11    50     3    54\r\n    31    52     5    71\r\n     1     3    98    47\r\n    28    86    93    55\r\n    71    55    16    93\r\n    84     1    68     7\r\n    17    64    98    33\r\n    76    19     2    72\r\n    72     1    56    73\r\n    13    92    67    14\r\n    49     9    92    37\r\n    44    28    83    76\r\n    56    78    58    20\r\n     6     3    75    90\r\n    96    21    63    10\r\n    59     2    60    72\r\n    17    65    28    98\r\n    34    46     5    41\r\n    48    56    54    47\r\n    76    95    90     8\r\n    57    35     5    54\r\n    26    30    13    73\r\n     6    49    17    46\r\n    23    59    82    56\r\n    55    46    46    33\r\n    80    15    42     6\r\n    78    57    59    22\r\n    96    11    69    23\r\n    72    58   100    42\r\n    88    48    23    23\r\n    16    35    48    32\r\n    11    45    79    61\r\n    95    82    31    63\r\n    19    49    73    19\r\n    65    14    81    41\r\n    12    81     4    30\r\n    70    24    33    82\r\n     7     5    66    14\r\n    98    79     3    37\r\n     9    81    91    72\r\n    50    62    99    11\r\n     9    66    18    58\r\n    35    38    29    61\r\n    36     9    44     5\r\n    98    25    92    84\r\n    53     9    33    18\r\n    85    80    93     6\r\n    60    56    25    10\r\n     9    29    90    32\r\n    36    98    38    84\r\n    26    64    21    21\r\n    52    36    58    48\r\n    92    15    35    18\r\n    62    37    98    67\r\n    79    53    24     9\r\n    12    62   100    65\r\n    30    26    24    61\r\n    84    12    29    17];\r\n     res1= [36    37    65    79];\r\n\r\n\r\n\r\n\r\n  res2=[ 46    48    87   100];\r\n  [v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n%%\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":5,"created_by":3838707,"edited_by":3838707,"edited_at":"2024-03-28T08:31:50.000Z","deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":"2024-03-28T08:31:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2024-03-27T20:22:32.000Z","updated_at":"2026-01-06T16:39:24.000Z","published_at":"2024-03-27T20:23:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003egiven a matrix with more than one row , compare row vectors of the given matrix and find the pair with the minumum angle between them , \\\"without using the dot fucntion\\\" \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\u003eyou can find the angle from the following formula\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e θ = cos-1 [ (a. b) / (|a| |b|) ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe product between the two vectors is the dot product \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e⋅\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e∑(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e​)*(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei)   from i=1 to n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e​\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe length of a vector is the square root of the sum of the squares of the components\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44468,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":163,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T22:09:37.000Z","updated_at":"2026-03-11T17:00:04.000Z","published_at":"2017-12-24T22:09:37.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44469,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":482,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2017-12-24T22:09:41.000Z","updated_at":"2026-02-14T08:55:51.000Z","published_at":"2017-12-24T22:09:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45395,"title":"Create a matrix map of increasing safety levels","description":"The sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.\r\n\r\nYou are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:\r\n\r\n# Assign _Safety Level 1_ to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.\r\n# Assign _Safety Level 2_ to the adjacent cells around the power plant, signifying a safer radiation level in this area.\r\n# Continue assigning an increasing number of _Safety Levels_ at succeeding layers of cells surrounding the power plant until you reach the edge of the map.\r\n\r\nWrite a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with _Safety Levels_. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:\r\n\r\n* N, R, C are all integers\r\n* 1 \u003c= N \u003c= 10\r\n* 1 \u003c= R \u003c= N and 1 \u003c= C \u003c= N\r\n\r\nHere are a few examples:\r\n\r\n  \u003e\u003e safety_map(5,5,4) % N = 5, R = 5, C = 4\r\n  ans =\r\n\r\n     5     5     5     5     5\r\n     4     4     4     4     4\r\n     4     3     3     3     3\r\n     4     3     2     2     2\r\n     4     3     2     1     2\r\n\u003e\u003e safety_map(6,2,3) % N = 6, R = 2, C = 3\r\nans =\r\n\r\n     3     2     2     2     3     4\r\n     3     2     1     2     3     4\r\n     3     2     2     2     3     4\r\n     3     3     3     3     3     4\r\n     4     4     4     4     4     4\r\n     5     5     5     5     5     5\r\n","description_html":"\u003cp\u003eThe sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.\u003c/p\u003e\u003cp\u003eYou are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:\u003c/p\u003e\u003col\u003e\u003cli\u003eAssign \u003ci\u003eSafety Level 1\u003c/i\u003e to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.\u003c/li\u003e\u003cli\u003eAssign \u003ci\u003eSafety Level 2\u003c/i\u003e to the adjacent cells around the power plant, signifying a safer radiation level in this area.\u003c/li\u003e\u003cli\u003eContinue assigning an increasing number of \u003ci\u003eSafety Levels\u003c/i\u003e at succeeding layers of cells surrounding the power plant until you reach the edge of the map.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eWrite a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with \u003ci\u003eSafety Levels\u003c/i\u003e. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:\u003c/p\u003e\u003cul\u003e\u003cli\u003eN, R, C are all integers\u003c/li\u003e\u003cli\u003e1 \u0026lt;= N \u0026lt;= 10\u003c/li\u003e\u003cli\u003e1 \u0026lt;= R \u0026lt;= N and 1 \u0026lt;= C \u0026lt;= N\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eHere are a few examples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; safety_map(5,5,4) % N = 5, R = 5, C = 4\r\nans =\r\n\u003c/pre\u003e\u003cpre\u003e     5     5     5     5     5\r\n     4     4     4     4     4\r\n     4     3     3     3     3\r\n     4     3     2     2     2\r\n     4     3     2     1     2\r\n\u0026gt;\u0026gt; safety_map(6,2,3) % N = 6, R = 2, C = 3\r\nans =\u003c/pre\u003e\u003cpre\u003e     3     2     2     2     3     4\r\n     3     2     1     2     3     4\r\n     3     2     2     2     3     4\r\n     3     3     3     3     3     4\r\n     4     4     4     4     4     4\r\n     5     5     5     5     5     5\u003c/pre\u003e","function_template":"function y = safety_map(N,R,C)\r\n  y = N;\r\nend","test_suite":"%%\r\ny_correct = [3 2 2 2 3 4; 3 2 1 2 3 4; ...\r\n3 2 2 2 3 4; 3 3 3 3 3 4; 4 4 4 4 4 4; ...\r\n5 5 5 5 5 5];\r\nassert(isequal(safety_map(6,2,3),y_correct))\r\n%%\r\ny_correct = [2 2;2 1];\r\nassert(isequal(safety_map(2,2,2),y_correct))\r\n%%\r\ny_correct = [9 8 7 6 5 4 3 2 1 2; ...\r\n9 8 7 6 5 4 3 2 2 2; 9 8 7 6 5 4 3 3 3 3; ...\r\n9 8 7 6 5 4 4 4 4 4; 9 8 7 6 5 5 5 5 5 5; ...\r\n9 8 7 6 6 6 6 6 6 6; 9 8 7 7 7 7 7 7 7 7; ...\r\n9 8 8 8 8 8 8 8 8 8; 9 9 9 9 9 9 9 9 9 9; ...\r\n10 10 10 10 10 10 10 10 10 10];\r\nassert(isequal(safety_map(10,1,9),y_correct))\r\n%%\r\ny_correct = 1;\r\nassert(isequal(safety_map(1,1,1),y_correct))\r\n%%\r\ny_correct = [4 3 2 2; ...\r\n4 3 2 1; 4 3 2 2; 4 3 3 3];\r\nassert(isequal(safety_map(4,2,4),y_correct))\r\n%%\r\ny_correct = [2 1;2 2];\r\nassert(isequal(safety_map(2,1,2),y_correct))\r\n%%\r\ny_correct = [4 4 4 4 4 4 4; 4 3 3 3 3 3 4; ...\r\n4 3 2 2 2 3 4; 4 3 2 1 2 3 4; 4 3 2 2 2 3 4; ...\r\n4 3 3 3 3 3 4; 4 4 4 4 4 4 4];\r\nassert(isequal(safety_map(7,4,4),y_correct))\r\n%%\r\ny_correct = [10 10 10 10 10 10 10 10 10 10; ...\r\n10 9 9 9 9 9 9 9 9 9; 10 9 8 8 8 8 8 8 8 8; ...\r\n10 9 8 7 7 7 7 7 7 7; 10 9 8 7 6 6 6 6 6 6; ...\r\n10 9 8 7 6 5 5 5 5 5; 10 9 8 7 6 5 4 4 4 4; ...\r\n10 9 8 7 6 5 4 3 3 3; 10 9 8 7 6 5 4 3 2 2; ...\r\n10 9 8 7 6 5 4 3 2 1];\r\nassert(isequal(safety_map(10,10,10),y_correct))\r\n%%\r\ny_correct = [3 3 3; 2 2 3; 1 2 3];\r\nassert(isequal(safety_map(3,3,1),y_correct))\r\n%%\r\ny_correct = [2 1 2; 2 2 2; 3 3 3];\r\nassert(isequal(safety_map(3,1,2),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2020-03-27T15:28:42.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-27T15:22:51.000Z","updated_at":"2026-03-31T14:20:57.000Z","published_at":"2020-03-27T15:22:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssign\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Level 1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssign\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Level 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the adjacent cells around the power plant, signifying a safer radiation level in this area.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eContinue assigning an increasing number of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Levels\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e at succeeding layers of cells surrounding the power plant until you reach the edge of the map.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Levels\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:\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\u003eN, R, C are all integers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 \u0026lt;= N \u0026lt;= 10\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 \u0026lt;= R \u0026lt;= N and 1 \u0026lt;= C \u0026lt;= N\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere are a few examples:\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[\u003e\u003e safety_map(5,5,4) % N = 5, R = 5, C = 4\\nans =\\n\\n     5     5     5     5     5\\n     4     4     4     4     4\\n     4     3     3     3     3\\n     4     3     2     2     2\\n     4     3     2     1     2\\n\u003e\u003e safety_map(6,2,3) % N = 6, R = 2, C = 3\\nans =\\n\\n     3     2     2     2     3     4\\n     3     2     1     2     3     4\\n     3     2     2     2     3     4\\n     3     3     3     3     3     4\\n     4     4     4     4     4     4\\n     5     5     5     5     5     5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44484,"title":"Separate even from odd numbers in a vector - with a loop","description":"*Using a loop*, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\n  Output: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\r\n  Input:  v = [2\r\n               7\r\n               0\r\n               3\r\n               2]\r\n\r\n  Output: w = [7\r\n               3\r\n               2\r\n               0\r\n               2]\r\n\r\n  Input:  v = []\r\n  Output: w = []\r\n","description_html":"\u003cp\u003e\u003cb\u003eUsing a loop\u003c/b\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [2\r\n             7\r\n             0\r\n             3\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput: w = [7\r\n             3\r\n             2\r\n             0\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = []\r\nOutput: w = []\r\n\u003c/pre\u003e","function_template":"function w = oddEven(v)\r\n    w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('oddEven.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('oddEven.m');\r\nloopUsed = ~isempty(strfind(filetext, 'while')) || ~isempty(strfind(filetext, 'for'));\r\nassert(loopUsed, 'Must use at least one loop')\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [2; 7; 0; 3; 2];\r\nw_correct = [7; 3; 2; 0; 2];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [1, 0, 2, 9, 3, 8, 8, 4];\r\nw_correct = [1, 9, 3, 0, 2, 8, 8, 4];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nodd  = 2 * randi([-4, 4], 1, randi([4,10])) - 1;\r\neven = 2 * randi([-4, 4], 1, randi([4,10]));\r\nv = [even, odd];\r\nw_correct = [odd, even];\r\nassert(isequal(oddEven(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":454,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T12:16:14.000Z","updated_at":"2026-02-11T19:24:54.000Z","published_at":"2018-01-07T12:16:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eUsing a loop\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\\n\\nInput:  v = [2\\n             7\\n             0\\n             3\\n             2]\\n\\nOutput: w = [7\\n             3\\n             2\\n             0\\n             2]\\n\\nInput:  v = []\\nOutput: w = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44455,"title":"Find the average of a random sequance","description":"Write a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\r\n\r\nAt each iteration a random integer between 0 and 10 is generated.\r\n\r\nOnly if the number is positive, it is added to the sequence.\r\n\r\nThe loop terminates when the number 0 is generated. This number is not considered for the mean.\r\n\r\n*You are not allowed to use the functions |sum()| and |mean()|*\r\n\r\nExamples:\r\n\r\n  Random sequence is: 4, 3, 5, 10, 3, 0\r\n  Output is: 5\r\n\r\n  Random sequence is: 0\r\n  Output is 0\r\n\r\n  Random sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\n  Output is: 4\r\n\r\n*Note*: the function does not have an input. The output depends on the state of the random numbers generator.","description_html":"\u003cp\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/p\u003e\u003cp\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/p\u003e\u003cp\u003eOnly if the number is positive, it is added to the sequence.\u003c/p\u003e\u003cp\u003eThe loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/p\u003e\u003cp\u003e\u003cb\u003eYou are not allowed to use the functions \u003ctt\u003esum()\u003c/tt\u003e and \u003ctt\u003emean()\u003c/tt\u003e\u003c/b\u003e\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 4, 3, 5, 10, 3, 0\r\nOutput is: 5\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 0\r\nOutput is 0\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\nOutput is: 4\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eNote\u003c/b\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\u003c/p\u003e","function_template":"function average = MeanWhile()\r\n    average = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'sum')),'sum() function is forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'mean')),'mean() function is forbidden')\r\n\r\n%%\r\nrng(1);\r\nav_correct = 5.5;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(2);\r\nav_correct = 4;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(3);\r\nav_correct = 5.25;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(7);\r\nav_correct = 0;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(0);\r\nav_correct = 6.571428571428571;\r\nassert(isequal(MeanWhile(),av_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":416,"test_suite_updated_at":"2017-12-17T07:32:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:37:19.000Z","updated_at":"2026-03-10T18:45:32.000Z","published_at":"2017-12-17T07:32:04.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnly if the number is positive, it is added to the sequence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eYou are not allowed to use the functions\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esum()\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emean()\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Random sequence is: 4, 3, 5, 10, 3, 0\\nOutput is: 5\\n\\nRandom sequence is: 0\\nOutput is 0\\n\\nRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\\nOutput is: 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44457,"title":"Triangle of numbers","description":"Create a matrix with the integers from 1 to |n| arranged in a triangular shape.\r\n\r\nEvery row |i| of the matrix contains |i| integers, and the rest of the elements are zeros.\r\n\r\nExamples:\r\n\r\n  Input:  n = 6\r\n  Output: mat = [1 0 0\r\n                 2 3 0\r\n                 4 5 6]\r\n\r\n  Input:  n = 12\r\n  Output: mat = [1  0  0  0 \r\n                 2  3  0  0 \r\n                 4  5  6  0 \r\n                 7  8  9  10\r\n                 11 12 0  0]","description_html":"\u003cp\u003eCreate a matrix with the integers from 1 to \u003ctt\u003en\u003c/tt\u003e arranged in a triangular shape.\u003c/p\u003e\u003cp\u003eEvery row \u003ctt\u003ei\u003c/tt\u003e of the matrix contains \u003ctt\u003ei\u003c/tt\u003e integers, and the rest of the elements are zeros.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 6\r\nOutput: mat = [1 0 0\r\n               2 3 0\r\n               4 5 6]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 12\r\nOutput: mat = [1  0  0  0 \r\n               2  3  0  0 \r\n               4  5  6  0 \r\n               7  8  9  10\r\n               11 12 0  0]\r\n\u003c/pre\u003e","function_template":"function mat = triangle(n)\r\n    mat = 1:n;\r\nend","test_suite":"%%\r\nfiletext = fileread('triangle.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nmat_correct = [];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 1;\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 6;\r\nmat_correct = [1 0 0; 2 3 0; 4 5 6];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 12;\r\nmat_correct = [1 0 0 0; 2 3 0 0; 4 5 6 0; 7 8 9 10; 11 12 0 0];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 50;\r\nmat_correct = [1,zeros(1,8); 2:3,zeros(1,7); 4:6,zeros(1,6);\r\n    7:10,zeros(1,5); 11:15,zeros(1,4); 16:21,zeros(1,3);\r\n    22:28,0,0; ; 29:36,0; 37:45; 46:50,zeros(1,4)];\r\nassert(isequal(triangle(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-17T08:43:23.000Z","updated_at":"2026-02-11T20:05:28.000Z","published_at":"2017-12-17T08:43:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate a matrix with the integers from 1 to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e arranged in a triangular shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the matrix contains\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e integers, and the rest of the elements are zeros.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n = 6\\nOutput: mat = [1 0 0\\n               2 3 0\\n               4 5 6]\\n\\nInput:  n = 12\\nOutput: mat = [1  0  0  0 \\n               2  3  0  0 \\n               4  5  6  0 \\n               7  8  9  10\\n               11 12 0  0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":3074,"title":"Compute the cokurtosis of a given portfolio.","description":"As input data, you are given a nObs-by-nAssets matrix _portRet_ of return series for assets in a portfolio along with an nAssets-by-1 vector _portWeights_ of portfolio weights. Example: \r\n\r\n \u003e\u003e nObs = 504; % Number of observations\r\n\r\n \u003e\u003e nAssets = 5; % Number of assets in the portfolio\r\n\r\n \u003e\u003e portRet = randn(nObs, nAssets); % Sample portfolio return series\r\n\r\n \u003e\u003e portWeights = rand(nAssets, 1); \r\n\r\n \u003e\u003e portWeights = portWeights/sum(portWeights); % Portfolio weights are \u003e=0 and sum to 1.\r\n\r\nThe task is to compute the *portfolio cokurtosis* , which is a scalar statistic associated with the portfolio. A full description of this statistic, along with sample MATLAB code for computing it, can be found here:\r\n\r\nhttp://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\r\n\r\nWrite a function that accepts _portRet_ and _portWeights_ as input arguments and returns the scalar statistic _portCokurt_ as its output. You can use the code at the website above as a starting point, but try to simplify and shorten it in the spirit of Cody.\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eAs input data, you are given a nObs-by-nAssets matrix \u003ci\u003eportRet\u003c/i\u003e of return series for assets in a portfolio along with an nAssets-by-1 vector \u003ci\u003eportWeights\u003c/i\u003e of portfolio weights. Example:\u003c/p\u003e\u003cpre\u003e \u0026gt;\u0026gt; nObs = 504; % Number of observations\u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; nAssets = 5; % Number of assets in the portfolio\u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; portRet = randn(nObs, nAssets); % Sample portfolio return series\u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; portWeights = rand(nAssets, 1); \u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; portWeights = portWeights/sum(portWeights); % Portfolio weights are \u0026gt;=0 and sum to 1.\u003c/pre\u003e\u003cp\u003eThe task is to compute the \u003cb\u003eportfolio cokurtosis\u003c/b\u003e , which is a scalar statistic associated with the portfolio. A full description of this statistic, along with sample MATLAB code for computing it, can be found here:\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\"\u003ehttp://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\u003c/a\u003e\u003c/p\u003e\u003cp\u003eWrite a function that accepts \u003ci\u003eportRet\u003c/i\u003e and \u003ci\u003eportWeights\u003c/i\u003e as input arguments and returns the scalar statistic \u003ci\u003eportCokurt\u003c/i\u003e as its output. You can use the code at the website above as a starting point, but try to simplify and shorten it in the spirit of Cody.\u003c/p\u003e","function_template":"function portCokurt = computePortCokurt(portRet, portWeights)\r\n\r\n\r\nend","test_suite":"%%\r\nrng('default')\r\nR = randn(504, 5);\r\nw = ones(5, 1)/5;\r\nassert(abs(computePortCokurt(R, w)-0.119749008958925)\u003c1e-3)\r\n\r\n%%\r\nrng('default')\r\nR = randn(252, 15);\r\nw = ones(15, 1)/15;\r\nassert(abs(computePortCokurt(R, w)-0.013012357540290)\u003c1e-3)\r\n\r\n%% \r\nrng('default')\r\nR = randn(100, 1);\r\nw = 1;\r\nassert(abs(computePortCokurt(R, w)-6.280759230562035)\u003c1e-3)\r\n\r\n%%\r\nrng('default')\r\nR = randn(5, 10);\r\nw = [0.1*ones(5, 1); 0.5; zeros(4, 1)];\r\nassert(abs(computePortCokurt(R, w)-0.169198885214440)\u003c1e-3)","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":2328,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-03-10T11:04:22.000Z","updated_at":"2015-03-11T18:00:35.000Z","published_at":"2015-03-10T11:25:35.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\u003eAs input data, you are given a nObs-by-nAssets matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportRet\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of return series for assets in a portfolio along with an nAssets-by-1 vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportWeights\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of portfolio weights. 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[ \u003e\u003e nObs = 504; % Number of observations\\n\\n \u003e\u003e nAssets = 5; % Number of assets in the portfolio\\n\\n \u003e\u003e portRet = randn(nObs, nAssets); % Sample portfolio return series\\n\\n \u003e\u003e portWeights = rand(nAssets, 1); \\n\\n \u003e\u003e portWeights = portWeights/sum(portWeights); % Portfolio weights are \u003e=0 and sum to 1.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe task is to compute the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportfolio cokurtosis\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , which is a scalar statistic associated with the portfolio. A full description of this statistic, along with sample MATLAB code for computing it, can be found here:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that accepts\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportRet\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportWeights\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as input arguments and returns the scalar statistic\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportCokurt\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as its output. You can use the code at the website above as a starting point, but try to simplify and shorten it in the spirit of Cody.\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":45394,"title":"Count the number of folds needed to pack a large sheet","description":"In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\r\n\r\n# Lay down a large sheet of paper of size X-by-Y feet.\r\n# _Fold_ the sheet in half so that the _larger_ length between X and Y is halved and the other length remains the same.\r\n# Repeat step 2 until _both_ lengths X and Y are _less_ than 1 foot.\r\n\r\nFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u003c= X \u003c= 4000 and 1 \u003c= Y \u003c= 4000. \r\n\r\nAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u003e (4,2.5) -\u003e (2,2.5) -\u003e (2,1.25) -\u003e (1,1.25) -\u003e (1,0.625) -\u003e (0.5,0.625). We stop because _both_ sizes are now less than 1. This takes a total of 6 folds.","description_html":"\u003cp\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/p\u003e\u003col\u003e\u003cli\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/li\u003e\u003cli\u003e\u003ci\u003eFold\u003c/i\u003e the sheet in half so that the \u003ci\u003elarger\u003c/i\u003e length between X and Y is halved and the other length remains the same.\u003c/li\u003e\u003cli\u003eRepeat step 2 until \u003ci\u003eboth\u003c/i\u003e lengths X and Y are \u003ci\u003eless\u003c/i\u003e than 1 foot.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/p\u003e\u003cp\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because \u003ci\u003eboth\u003c/i\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/p\u003e","function_template":"function y = number_of_folds(X,Y)\r\n  y = X;\r\nend","test_suite":"%%\r\nassert(isequal(number_of_folds(3247,2132),24))\r\n%%\r\nassert(isequal(number_of_folds(1403,3757),23))\r\n%%\r\nassert(isequal(number_of_folds(3504,2201),24))\r\n%%\r\nassert(isequal(number_of_folds(2490,2349),24))\r\n%%\r\nassert(isequal(number_of_folds(831,1205),21))\r\n%%\r\nassert(isequal(number_of_folds(1884,922),21))\r\n%%\r\nassert(isequal(number_of_folds(2,4),5))\r\n%%\r\nassert(isequal(number_of_folds(3378,780),22))\r\n%%\r\nassert(isequal(number_of_folds(904,683),20))\r\n%%\r\nassert(isequal(number_of_folds(911,1743),21))\r\n%%\r\nassert(isequal(number_of_folds(1245,3694),23))\r\n%%\r\nassert(isequal(number_of_folds(1721,740),21))\r\n%%\r\nassert(isequal(number_of_folds(3620,3919),24))\r\n%%\r\nassert(isequal(number_of_folds(1756,445),20))\r\n%%\r\nassert(isequal(number_of_folds(1033,1635),22))\r\n%%\r\nassert(isequal(number_of_folds(2380,1049),23))\r\n%%\r\nassert(isequal(number_of_folds(2412,2845),24))\r\n%%\r\nassert(isequal(number_of_folds(887,470),19))\r\n%%\r\nassert(isequal(number_of_folds(1187,1276),22))\r\n%%\r\nassert(isequal(number_of_folds(1697,2032),22))\r\n%%\r\nassert(isequal(number_of_folds(343,1050),20))\r\n%%\r\nassert(isequal(number_of_folds(3205,117),19))\r\n%%\r\nassert(isequal(number_of_folds(3716,2922),24))\r\n%%\r\nassert(isequal(number_of_folds(1955,2315),23))\r\n%%\r\nassert(isequal(number_of_folds(950,1836),21))\r\n%%\r\nassert(isequal(number_of_folds(3853,2188),24))\r\n%%\r\nassert(isequal(number_of_folds(2085,927),22))\r\n%%\r\nassert(isequal(number_of_folds(1956,2497),23))\r\n%%\r\nassert(isequal(number_of_folds(2717,1583),23))\r\n%%\r\nassert(isequal(number_of_folds(1470,3952),23))\r\n%%\r\nassert(isequal(number_of_folds(151,3541),20))\r\n%%\r\nassert(isequal(number_of_folds(3654,3185),24))\r\n%%\r\nassert(isequal(number_of_folds(395,1048),20))\r\n%%\r\nassert(isequal(number_of_folds(1342,2719),23))\r\n%%\r\nassert(isequal(number_of_folds(547,2885),22))\r\n%%\r\nassert(isequal(number_of_folds(428,2616),21))\r\n%%\r\nassert(isequal(number_of_folds(1977,3117),23))\r\n%%\r\nassert(isequal(number_of_folds(2861,3615),24))\r\n%%\r\nassert(isequal(number_of_folds(3564,1337),23))\r\n%%\r\nassert(isequal(number_of_folds(1,4000),13))\r\n%%\r\nassert(isequal(number_of_folds(2795,792),22))\r\n%%\r\nassert(isequal(number_of_folds(123,2977),19))\r\n%%\r\nassert(isequal(number_of_folds(2001,1920),22))\r\n%%\r\nassert(isequal(number_of_folds(3619,2440),24))\r\n%%\r\nassert(isequal(number_of_folds(2471,3438),24))\r\n%%\r\nassert(isequal(number_of_folds(3222,2307),24))\r\n%%\r\nassert(isequal(number_of_folds(732,960),20))\r\n%%\r\nassert(isequal(number_of_folds(3547,115),19))\r\n%%\r\nassert(isequal(number_of_folds(1960,672),21))\r\n%%\r\nassert(isequal(number_of_folds(3915,2851),24))\r\n%%\r\nassert(isequal(number_of_folds(2002,1885),22))\r\n%%\r\nassert(isequal(number_of_folds(239,2728),20))\r\n%%\r\nassert(isequal(number_of_folds(170,286),17))\r\n%%\r\nassert(isequal(number_of_folds(2087,387),21))\r\n%%\r\nassert(isequal(number_of_folds(3273,3271),24))\r\n%%\r\nassert(isequal(number_of_folds(2890,600),22))\r\n%%\r\nassert(isequal(number_of_folds(2639,2075),24))\r\n%%\r\nassert(isequal(number_of_folds(3892,2596),24))\r\n%%\r\nassert(isequal(number_of_folds(3202,1816),23))\r\n%%\r\nassert(isequal(number_of_folds(1730,3302),23))\r\n%%\r\nassert(isequal(number_of_folds(334,533),19))\r\n%%\r\nassert(isequal(number_of_folds(694,1564),21))\r\n%%\r\nassert(isequal(number_of_folds(3326,3214),24))\r\n%%\r\nassert(isequal(number_of_folds(242,1598),19))\r\n%%\r\nassert(isequal(number_of_folds(2108,1668),23))\r\n%%\r\nassert(isequal(number_of_folds(2628,2512),24))\r\n%%\r\nassert(isequal(number_of_folds(1168,1727),22))\r\n%%\r\nassert(isequal(number_of_folds(62,3937),18))\r\n%%\r\nassert(isequal(number_of_folds(669,425),19))\r\n%%\r\nassert(isequal(number_of_folds(1490,793),21))\r\n%%\r\nassert(isequal(number_of_folds(1959,1358),22))\r\n%%\r\nassert(isequal(number_of_folds(3807,3682),24))\r\n%%\r\nassert(isequal(number_of_folds(211,2952),20))\r\n%%\r\nassert(isequal(number_of_folds(1077,1692),22))\r\n%%\r\nassert(isequal(number_of_folds(2192,3771),24))\r\n%%\r\nassert(isequal(number_of_folds(1,1),2))\r\n%%\r\nassert(isequal(number_of_folds(1671,3933),23))\r\n%%\r\nassert(isequal(number_of_folds(1206,2805),23))\r\n%%\r\nassert(isequal(number_of_folds(2666,2157),24))\r\n%%\r\nassert(isequal(number_of_folds(2793,2667),24))\r\n%%\r\nassert(isequal(number_of_folds(713,513),20))\r\n%%\r\nassert(isequal(number_of_folds(3997,685),22))\r\n%%\r\nassert(isequal(number_of_folds(131,2245),20))\r\n%%\r\nassert(isequal(number_of_folds(3528,2677),24))\r\n%%\r\nassert(isequal(number_of_folds(762,1476),21))\r\n%%\r\nassert(isequal(number_of_folds(1843,3927),23))\r\n%%\r\nassert(isequal(number_of_folds(626,3423),22))\r\n%%\r\nassert(isequal(number_of_folds(2580,1506),23))\r\n%%\r\nassert(isequal(number_of_folds(764,1714),21))\r\n%%\r\nassert(isequal(number_of_folds(1929,483),20))\r\n%%\r\nassert(isequal(number_of_folds(2359,905),22))\r\n%%\r\nassert(isequal(number_of_folds(1539,2332),23))\r\n%%\r\nassert(isequal(number_of_folds(1008,1162),21))\r\n%%\r\nassert(isequal(number_of_folds(2469,1062),23))\r\n%%\r\nassert(isequal(number_of_folds(15,15),8))\r\n%%\r\nassert(isequal(number_of_folds(3298,3931),24))\r\n%%\r\nassert(isequal(number_of_folds(2921,1376),23))\r\n%%\r\nassert(isequal(number_of_folds(2337,432),21))\r\n%%\r\nassert(isequal(number_of_folds(3626,3519),24))\r\n%%\r\nassert(isequal(number_of_folds(3272,1043),23))\r\n%%\r\nassert(isequal(number_of_folds(3,2),4))\r\n%%\r\nassert(isequal(number_of_folds(2378,91),19))\r\n%%\r\nassert(isequal(number_of_folds(1702,1251),22))\r\n%%\r\nassert(isequal(number_of_folds(646,716),20))\r\n%%\r\nassert(isequal(number_of_folds(1692,377),20))\r\n%%\r\nassert(isequal(number_of_folds(16,15),9))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":115,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-26T22:22:34.000Z","updated_at":"2026-03-31T14:22:20.000Z","published_at":"2020-03-26T22:22:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFold\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the sheet in half so that the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elarger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e length between X and Y is halved and the other length remains the same.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRepeat step 2 until\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e lengths X and Y are\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eless\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e than 1 foot.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44901,"title":"Rearrange the given matrix to have all its zeros climb up to the top of each column - using for loops.","description":"Given a matrix x, *using loops only* return a matrix y, in which all the zeros have \"climbed\" up to the top. That is, any zeros in each column should be moved to the top without disturbing The order of the remaining nonzero numbers in the column.","description_html":"\u003cp\u003eGiven a matrix x, \u003cb\u003eusing loops only\u003c/b\u003e return a matrix y, in which all the zeros have \"climbed\" up to the top. That is, any zeros in each column should be moved to the top without disturbing The order of the remaining nonzero numbers in the column.\u003c/p\u003e","function_template":"function y = zerosFirst(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [0     0     1     1\r\n     0     1    -1    -1\r\n     2     1    -1     2\r\n     2     2     0     0\r\n    -1     0     2     1\r\n     0     1     0     1];\r\n \r\ny_correct = [0     0     0     0\r\n             0     0     0     1\r\n             0     1     1    -1\r\n             2     1    -1     2\r\n             2     2    -1     1\r\n            -1     1     2     1];\r\n        \r\nassert(isequal(zerosFirst(x),y_correct))\r\n\r\n%%\r\nx = [12 56 0 0 65 122 0 37]'\r\n\r\ny_correct = [0     0     0    12    56    65   122    37]'\r\n        \r\nassert(isequal(zerosFirst(x),y_correct))\r\n\r\n%%\r\nfiletext = fileread('zerosFirst.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\t\r\n%%\r\nfiletext = fileread('zerosFirst.m');\r\nassert(~isempty(strfind(filetext, 'for')),'must use a for loop in solving this problem')\r\n%%\r\nfiletext = fileread('zerosFirst.m');\r\nassert(isempty(strfind(filetext, '!echo')),'!echo hacks are forbidden')\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":278101,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-05-19T11:15:18.000Z","updated_at":"2025-11-29T16:22:51.000Z","published_at":"2019-05-19T11:15:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix x,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eusing loops only\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e return a matrix y, in which all the zeros have \\\"climbed\\\" up to the top. That is, any zeros in each column should be moved to the top without disturbing The order of the remaining nonzero numbers in the column.\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":60791,"title":"Sum of Even Fibonacci Numbers","description":"Description:\r\nThe Fibonacci sequence is defined as follows:F(1)=1,F(2)=1,F(n)=F(n−1)+F(n−2) for n\u003e2\r\nWrite a function that computes the sum of all even Fibonacci numbers that do not exceed a given number NNN.\r\nExample:\r\nFor N=10, the Fibonacci sequence up to 10 is:\r\n1,1,2,3,5,8\r\nThe even numbers are 2 and 8, and their sum is 10.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 201px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 100.5px; transform-origin: 407px 100.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eDescription:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Fibonacci sequence is defined as follows:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e−\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e+\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eF\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e−\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e for \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u0026gt;\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that computes the sum of \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eall even Fibonacci numbers\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e that do not exceed a given number \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e10, the Fibonacci sequence up to 10 is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e5\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e8\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe even numbers are \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e2 and 8\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and their sum is \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e10\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function sum_even_fib = even_fibonacci_sum(N)\r\n    % Write your code here\r\nend\r\n","test_suite":"%% Test 1: Basic Case\r\nx = 10;\r\ny_correct = 10; % (2 + 8)\r\nassert(isequal(even_fibonacci_sum(x), y_correct))\r\n\r\n%% Test 2: Larger N\r\nx = 34;\r\ny_correct = 44; % (2 + 8 + 34)\r\nassert(isequal(even_fibonacci_sum(x), y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":383919,"edited_by":383919,"edited_at":"2025-02-10T11:48:53.000Z","deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-02-10T11:47:18.000Z","updated_at":"2025-11-14T09:05:50.000Z","published_at":"2025-02-10T11:48:53.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Fibonacci sequence is defined as follows:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e−\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e+\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e−\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that computes the sum of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall even Fibonacci numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that do not exceed a given number \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e10, the Fibonacci sequence up to 10 is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe even numbers are \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2 and 8\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and their sum is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e10\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44454,"title":"How many Integers?","description":"Count the integers in a given vector |v|.\r\n\r\nYou *must* use a loop to count each element separately.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\n  Output: n = 6    (9.0 is also an integer)\r\n\r\n  Input:  v = [1.2, 2.3, 4.5]\r\n  Output: n = 0","description_html":"\u003cp\u003eCount the integers in a given vector \u003ctt\u003ev\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eYou \u003cb\u003emust\u003c/b\u003e use a loop to count each element separately.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nOutput: n = 6    (9.0 is also an integer)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1.2, 2.3, 4.5]\r\nOutput: n = 0\r\n\u003c/pre\u003e","function_template":"function n = integerCount(v)\r\n    % write your code instead of this line\r\n    n = length(v);\r\n    % \r\nend","test_suite":"%%\r\nfiletext = fileread('integerCount.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nv = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\r\nn_correct = 6;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = [1.6, 5.7, 4.8, -3.5, 5.3, 9.2, -1.1, 0.01, 1.2]\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n\r\n%%\r\nv = []\r\nn_correct = 0;\r\nassert(isequal(integerCount(v),n_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":464,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:23:07.000Z","updated_at":"2026-02-11T15:35:06.000Z","published_at":"2017-12-16T22:23:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCount the integers in a given vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emust\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use a loop to count each element separately.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  v = [1.6, 5.7, 8, -3, 5.3, 9.0, -1, 0, 12]\\nOutput: n = 6    (9.0 is also an integer)\\n\\nInput:  v = [1.2, 2.3, 4.5]\\nOutput: n = 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":59721,"title":"finding vector pair with min angle between them","description":"given a matrix with more than one row , compare row vectors of the given matrix and find the pair with the minumum angle between them , \"without using the dot fucntion\" \r\nyou can find the angle from the following formula\r\n θ = cos-1 [ (a. b) / (|a| |b|) ]\r\nthe product between the two vectors is the dot product \r\na⋅b=∑(ai​)*(bi)   from i=1 to n​\r\nthe length of a vector is the square root of the sum of the squares of the components\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.440001px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 222px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 111px; transform-origin: 407px 111px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003egiven a matrix with more than one row , compare row vectors of the given matrix and find the pair with the minumum angle between them , \"without using the dot fucntion\" \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eyou can find the angle from the following formula\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e θ = cos-1 [ (a. b) / (|a| |b|) ]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ethe product between the two vectors is the dot product \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ea\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e⋅\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eb\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e∑(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ea\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ei\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e​)*(\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eb\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ei)   from i=1 to n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e​\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ethe length of a vector is the square root of the sum of the squares of the components\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [v1 v2] = minAngle(mat)\r\n   \r\nend","test_suite":"%%\r\nmat = [ 155    12   344   356\r\n   305   234   135    40\r\n   227    13   316   310\r\n   266    72    51   178\r\n     8   195   166   289];\r\nres1=[155    12   344   356];\r\nres2=[227    13   316   310];\r\n[v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n\r\n%%\r\nmat=[  2    50    47\r\n    24    99    24\r\n    89    23    42\r\n    13    37     9\r\n    66     5    83\r\n     2     5    95\r\n    60    28     3\r\n    52    84    13\r\n    87    35    14\r\n    37    93    17\r\n    80    43   100\r\n    20    16    98\r\n    27    41     3\r\n    59    86    76\r\n    22    56    26\r\n    99    68    42\r\n    13    94    40];\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n res1=[   13    37     9];\r\n  res2=[  37    93    17];\r\n [v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n\r\n%%\r\nmat=[ 79     4    66    79    23\r\n    22    42    94     3    25\r\n    78    36    58    16    71\r\n    55    52    23    23     8\r\n    67     3     4    80    82\r\n    96    74    85    74    98];\r\n\r\n   res1=[ 78    36    58    16    71];\r\n\r\n\r\n\r\n   res2=[ 96    74    85    74    98];\r\n    [v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n\r\n %%\r\n  mat=[ 8    47    50    69\r\n    78    49    11    83\r\n    68    53    63    98\r\n    97    74   100    57\r\n     4    48    24    91\r\n    96    46    12    92\r\n    64    61     4     1\r\n    73    61    72    71\r\n    78     6    47    63\r\n    52    34    18    41\r\n    46     3    95    38\r\n   100    10    52     2\r\n    88    71    59    25\r\n    63    33    99    43\r\n    95    56    48    44\r\n    73     6    13    14\r\n    56    60     8    84\r\n    96    60     7    85\r\n     8    90    54    76\r\n     1     6    39    70\r\n    83    12    18    44\r\n    44     9    85    11\r\n    65    43    17    90\r\n    44    68    36    34\r\n    92    89    46    89\r\n    36    37    65    79\r\n    11    69    76    41\r\n    41    17    23    56\r\n    94    10    16     7\r\n    51    98    17    70\r\n    94    18    53    11\r\n    45     9    38    42\r\n    59    99    32    31\r\n    81    85    12    82\r\n    46    48    87   100\r\n    52    17    78    17\r\n    35    55    61    57\r\n    46    55    22    93\r\n    52    51    31    10\r\n    84    56    31    34\r\n    77    51    62    66\r\n    41    88    17    40\r\n    90    62    86    20\r\n    86    50    60    48\r\n    11    50     3    54\r\n    31    52     5    71\r\n     1     3    98    47\r\n    28    86    93    55\r\n    71    55    16    93\r\n    84     1    68     7\r\n    17    64    98    33\r\n    76    19     2    72\r\n    72     1    56    73\r\n    13    92    67    14\r\n    49     9    92    37\r\n    44    28    83    76\r\n    56    78    58    20\r\n     6     3    75    90\r\n    96    21    63    10\r\n    59     2    60    72\r\n    17    65    28    98\r\n    34    46     5    41\r\n    48    56    54    47\r\n    76    95    90     8\r\n    57    35     5    54\r\n    26    30    13    73\r\n     6    49    17    46\r\n    23    59    82    56\r\n    55    46    46    33\r\n    80    15    42     6\r\n    78    57    59    22\r\n    96    11    69    23\r\n    72    58   100    42\r\n    88    48    23    23\r\n    16    35    48    32\r\n    11    45    79    61\r\n    95    82    31    63\r\n    19    49    73    19\r\n    65    14    81    41\r\n    12    81     4    30\r\n    70    24    33    82\r\n     7     5    66    14\r\n    98    79     3    37\r\n     9    81    91    72\r\n    50    62    99    11\r\n     9    66    18    58\r\n    35    38    29    61\r\n    36     9    44     5\r\n    98    25    92    84\r\n    53     9    33    18\r\n    85    80    93     6\r\n    60    56    25    10\r\n     9    29    90    32\r\n    36    98    38    84\r\n    26    64    21    21\r\n    52    36    58    48\r\n    92    15    35    18\r\n    62    37    98    67\r\n    79    53    24     9\r\n    12    62   100    65\r\n    30    26    24    61\r\n    84    12    29    17];\r\n     res1= [36    37    65    79];\r\n\r\n\r\n\r\n\r\n  res2=[ 46    48    87   100];\r\n  [v1 v2]=minAngle(mat);\r\nassert(isequal([v1 v2],[res1 res2]))\r\n%%\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":5,"created_by":3838707,"edited_by":3838707,"edited_at":"2024-03-28T08:31:50.000Z","deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":"2024-03-28T08:31:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2024-03-27T20:22:32.000Z","updated_at":"2026-01-06T16:39:24.000Z","published_at":"2024-03-27T20:23:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003egiven a matrix with more than one row , compare row vectors of the given matrix and find the pair with the minumum angle between them , \\\"without using the dot fucntion\\\" \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\u003eyou can find the angle from the following formula\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e θ = cos-1 [ (a. b) / (|a| |b|) ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe product between the two vectors is the dot product \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e⋅\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e∑(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e​)*(\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei)   from i=1 to n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e​\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe length of a vector is the square root of the sum of the squares of the components\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":44468,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":163,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-24T22:09:37.000Z","updated_at":"2026-03-11T17:00:04.000Z","published_at":"2017-12-24T22:09:37.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44469,"title":"Diagonal Pattern","description":"For a positive integer |n|, return an |nXn| matrix |mat| such that the value of each element in row |i| and column |j| is given according to the following rules:\r\n\r\n* |i - j|, if |i \u003e j|\r\n* |j - i|, if |i \u003c j|\r\n* |0|,   if |i| equals |j|\r\n\r\nIf |n| is not a positive integer, |mat| should be an empty matrix.\r\n\r\nExamples:\r\n\r\n  Input:  n   = 4\r\n  Output: mat = [0  1  2  3\r\n                 1  0  1  2\r\n                 2  1  0  1\r\n                 3  2  1  0]\r\n\r\n  Input:  n   = -2\r\n  Output: mat = []\r\n\r\n  Input:  n   = 2.5\r\n  Output: mat = []\r\n","description_html":"\u003cp\u003eFor a positive integer \u003ctt\u003en\u003c/tt\u003e, return an \u003ctt\u003enXn\u003c/tt\u003e matrix \u003ctt\u003emat\u003c/tt\u003e such that the value of each element in row \u003ctt\u003ei\u003c/tt\u003e and column \u003ctt\u003ej\u003c/tt\u003e is given according to the following rules:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003ei - j\u003c/tt\u003e, if \u003ctt\u003ei \u0026gt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003ej - i\u003c/tt\u003e, if \u003ctt\u003ei \u0026lt; j\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003e0\u003c/tt\u003e,   if \u003ctt\u003ei\u003c/tt\u003e equals \u003ctt\u003ej\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIf \u003ctt\u003en\u003c/tt\u003e is not a positive integer, \u003ctt\u003emat\u003c/tt\u003e should be an empty matrix.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 4\r\nOutput: mat = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = -2\r\nOutput: mat = []\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n   = 2.5\r\nOutput: mat = []\r\n\u003c/pre\u003e","function_template":"function mat = diagonalPattern(n)\r\n    mat = diag(n);\r\nend","test_suite":"%%\r\nfiletext = fileread('diagonalPattern.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 0;\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = -1;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 1.5;\r\nmat_correct = [];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 4;\r\nmat_correct = [0  1  2  3\r\n               1  0  1  2\r\n               2  1  0  1\r\n               3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n\r\n%%\r\nn = 5;\r\nmat_correct = [0  1  2  3  4\r\n               1  0  1  2  3\r\n               2  1  0  1  2\r\n               3  2  1  0  1\r\n               4  3  2  1  0];\r\nassert(isequal(diagonalPattern(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":482,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2017-12-24T22:09:41.000Z","updated_at":"2026-02-14T08:55:51.000Z","published_at":"2017-12-24T22:09:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enXn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e such that the value of each element in row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is given according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei - j\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026gt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej - i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei \u0026lt; j\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, if\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ej\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is not a positive integer,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emat\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should be an empty matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n   = 4\\nOutput: mat = [0  1  2  3\\n               1  0  1  2\\n               2  1  0  1\\n               3  2  1  0]\\n\\nInput:  n   = -2\\nOutput: mat = []\\n\\nInput:  n   = 2.5\\nOutput: mat = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45395,"title":"Create a matrix map of increasing safety levels","description":"The sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.\r\n\r\nYou are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:\r\n\r\n# Assign _Safety Level 1_ to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.\r\n# Assign _Safety Level 2_ to the adjacent cells around the power plant, signifying a safer radiation level in this area.\r\n# Continue assigning an increasing number of _Safety Levels_ at succeeding layers of cells surrounding the power plant until you reach the edge of the map.\r\n\r\nWrite a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with _Safety Levels_. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:\r\n\r\n* N, R, C are all integers\r\n* 1 \u003c= N \u003c= 10\r\n* 1 \u003c= R \u003c= N and 1 \u003c= C \u003c= N\r\n\r\nHere are a few examples:\r\n\r\n  \u003e\u003e safety_map(5,5,4) % N = 5, R = 5, C = 4\r\n  ans =\r\n\r\n     5     5     5     5     5\r\n     4     4     4     4     4\r\n     4     3     3     3     3\r\n     4     3     2     2     2\r\n     4     3     2     1     2\r\n\u003e\u003e safety_map(6,2,3) % N = 6, R = 2, C = 3\r\nans =\r\n\r\n     3     2     2     2     3     4\r\n     3     2     1     2     3     4\r\n     3     2     2     2     3     4\r\n     3     3     3     3     3     4\r\n     4     4     4     4     4     4\r\n     5     5     5     5     5     5\r\n","description_html":"\u003cp\u003eThe sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.\u003c/p\u003e\u003cp\u003eYou are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:\u003c/p\u003e\u003col\u003e\u003cli\u003eAssign \u003ci\u003eSafety Level 1\u003c/i\u003e to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.\u003c/li\u003e\u003cli\u003eAssign \u003ci\u003eSafety Level 2\u003c/i\u003e to the adjacent cells around the power plant, signifying a safer radiation level in this area.\u003c/li\u003e\u003cli\u003eContinue assigning an increasing number of \u003ci\u003eSafety Levels\u003c/i\u003e at succeeding layers of cells surrounding the power plant until you reach the edge of the map.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eWrite a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with \u003ci\u003eSafety Levels\u003c/i\u003e. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:\u003c/p\u003e\u003cul\u003e\u003cli\u003eN, R, C are all integers\u003c/li\u003e\u003cli\u003e1 \u0026lt;= N \u0026lt;= 10\u003c/li\u003e\u003cli\u003e1 \u0026lt;= R \u0026lt;= N and 1 \u0026lt;= C \u0026lt;= N\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eHere are a few examples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; safety_map(5,5,4) % N = 5, R = 5, C = 4\r\nans =\r\n\u003c/pre\u003e\u003cpre\u003e     5     5     5     5     5\r\n     4     4     4     4     4\r\n     4     3     3     3     3\r\n     4     3     2     2     2\r\n     4     3     2     1     2\r\n\u0026gt;\u0026gt; safety_map(6,2,3) % N = 6, R = 2, C = 3\r\nans =\u003c/pre\u003e\u003cpre\u003e     3     2     2     2     3     4\r\n     3     2     1     2     3     4\r\n     3     2     2     2     3     4\r\n     3     3     3     3     3     4\r\n     4     4     4     4     4     4\r\n     5     5     5     5     5     5\u003c/pre\u003e","function_template":"function y = safety_map(N,R,C)\r\n  y = N;\r\nend","test_suite":"%%\r\ny_correct = [3 2 2 2 3 4; 3 2 1 2 3 4; ...\r\n3 2 2 2 3 4; 3 3 3 3 3 4; 4 4 4 4 4 4; ...\r\n5 5 5 5 5 5];\r\nassert(isequal(safety_map(6,2,3),y_correct))\r\n%%\r\ny_correct = [2 2;2 1];\r\nassert(isequal(safety_map(2,2,2),y_correct))\r\n%%\r\ny_correct = [9 8 7 6 5 4 3 2 1 2; ...\r\n9 8 7 6 5 4 3 2 2 2; 9 8 7 6 5 4 3 3 3 3; ...\r\n9 8 7 6 5 4 4 4 4 4; 9 8 7 6 5 5 5 5 5 5; ...\r\n9 8 7 6 6 6 6 6 6 6; 9 8 7 7 7 7 7 7 7 7; ...\r\n9 8 8 8 8 8 8 8 8 8; 9 9 9 9 9 9 9 9 9 9; ...\r\n10 10 10 10 10 10 10 10 10 10];\r\nassert(isequal(safety_map(10,1,9),y_correct))\r\n%%\r\ny_correct = 1;\r\nassert(isequal(safety_map(1,1,1),y_correct))\r\n%%\r\ny_correct = [4 3 2 2; ...\r\n4 3 2 1; 4 3 2 2; 4 3 3 3];\r\nassert(isequal(safety_map(4,2,4),y_correct))\r\n%%\r\ny_correct = [2 1;2 2];\r\nassert(isequal(safety_map(2,1,2),y_correct))\r\n%%\r\ny_correct = [4 4 4 4 4 4 4; 4 3 3 3 3 3 4; ...\r\n4 3 2 2 2 3 4; 4 3 2 1 2 3 4; 4 3 2 2 2 3 4; ...\r\n4 3 3 3 3 3 4; 4 4 4 4 4 4 4];\r\nassert(isequal(safety_map(7,4,4),y_correct))\r\n%%\r\ny_correct = [10 10 10 10 10 10 10 10 10 10; ...\r\n10 9 9 9 9 9 9 9 9 9; 10 9 8 8 8 8 8 8 8 8; ...\r\n10 9 8 7 7 7 7 7 7 7; 10 9 8 7 6 6 6 6 6 6; ...\r\n10 9 8 7 6 5 5 5 5 5; 10 9 8 7 6 5 4 4 4 4; ...\r\n10 9 8 7 6 5 4 3 3 3; 10 9 8 7 6 5 4 3 2 2; ...\r\n10 9 8 7 6 5 4 3 2 1];\r\nassert(isequal(safety_map(10,10,10),y_correct))\r\n%%\r\ny_correct = [3 3 3; 2 2 3; 1 2 3];\r\nassert(isequal(safety_map(3,3,1),y_correct))\r\n%%\r\ny_correct = [2 1 2; 2 2 2; 3 3 3];\r\nassert(isequal(safety_map(3,1,2),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":"2020-03-27T15:28:42.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-27T15:22:51.000Z","updated_at":"2026-03-31T14:20:57.000Z","published_at":"2020-03-27T15:22:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssign\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Level 1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssign\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Level 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to the adjacent cells around the power plant, signifying a safer radiation level in this area.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eContinue assigning an increasing number of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Levels\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e at succeeding layers of cells surrounding the power plant until you reach the edge of the map.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSafety Levels\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:\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\u003eN, R, C are all integers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 \u0026lt;= N \u0026lt;= 10\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 \u0026lt;= R \u0026lt;= N and 1 \u0026lt;= C \u0026lt;= N\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere are a few examples:\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[\u003e\u003e safety_map(5,5,4) % N = 5, R = 5, C = 4\\nans =\\n\\n     5     5     5     5     5\\n     4     4     4     4     4\\n     4     3     3     3     3\\n     4     3     2     2     2\\n     4     3     2     1     2\\n\u003e\u003e safety_map(6,2,3) % N = 6, R = 2, C = 3\\nans =\\n\\n     3     2     2     2     3     4\\n     3     2     1     2     3     4\\n     3     2     2     2     3     4\\n     3     3     3     3     3     4\\n     4     4     4     4     4     4\\n     5     5     5     5     5     5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44484,"title":"Separate even from odd numbers in a vector - with a loop","description":"*Using a loop*, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\r\n\r\nExamples:\r\n\r\n  Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\n  Output: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\r\n  Input:  v = [2\r\n               7\r\n               0\r\n               3\r\n               2]\r\n\r\n  Output: w = [7\r\n               3\r\n               2\r\n               0\r\n               2]\r\n\r\n  Input:  v = []\r\n  Output: w = []\r\n","description_html":"\u003cp\u003e\u003cb\u003eUsing a loop\u003c/b\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [1, 0, 2, 9, 3, 8, 8, 4]\r\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = [2\r\n             7\r\n             0\r\n             3\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput: w = [7\r\n             3\r\n             2\r\n             0\r\n             2]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  v = []\r\nOutput: w = []\r\n\u003c/pre\u003e","function_template":"function w = oddEven(v)\r\n    w = v;\r\nend","test_suite":"%%\r\nfiletext = fileread('oddEven.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('oddEven.m');\r\nloopUsed = ~isempty(strfind(filetext, 'while')) || ~isempty(strfind(filetext, 'for'));\r\nassert(loopUsed, 'Must use at least one loop')\r\n\r\n%%\r\nv = [];\r\nw_correct = [];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [2; 7; 0; 3; 2];\r\nw_correct = [7; 3; 2; 0; 2];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nv = [1, 0, 2, 9, 3, 8, 8, 4];\r\nw_correct = [1, 9, 3, 0, 2, 8, 8, 4];\r\nassert(isequal(oddEven(v),w_correct))\r\n\r\n%%\r\nodd  = 2 * randi([-4, 4], 1, randi([4,10])) - 1;\r\neven = 2 * randi([-4, 4], 1, randi([4,10]));\r\nv = [even, odd];\r\nw_correct = [odd, even];\r\nassert(isequal(oddEven(v),w_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":454,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-07T12:16:14.000Z","updated_at":"2026-02-11T19:24:54.000Z","published_at":"2018-01-07T12:16:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eUsing a loop\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rearrange a vector of integers such that the odd numbers appear at the beginning, and even numbers at the end. The order within each group should be preserved.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  v = [1, 0, 2, 9, 3, 8, 8, 4]\\nOutput: w = [1, 9, 3, 0, 2, 8, 8, 4]\\n\\nInput:  v = [2\\n             7\\n             0\\n             3\\n             2]\\n\\nOutput: w = [7\\n             3\\n             2\\n             0\\n             2]\\n\\nInput:  v = []\\nOutput: w = []]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44455,"title":"Find the average of a random sequance","description":"Write a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\r\n\r\nAt each iteration a random integer between 0 and 10 is generated.\r\n\r\nOnly if the number is positive, it is added to the sequence.\r\n\r\nThe loop terminates when the number 0 is generated. This number is not considered for the mean.\r\n\r\n*You are not allowed to use the functions |sum()| and |mean()|*\r\n\r\nExamples:\r\n\r\n  Random sequence is: 4, 3, 5, 10, 3, 0\r\n  Output is: 5\r\n\r\n  Random sequence is: 0\r\n  Output is 0\r\n\r\n  Random sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\n  Output is: 4\r\n\r\n*Note*: the function does not have an input. The output depends on the state of the random numbers generator.","description_html":"\u003cp\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/p\u003e\u003cp\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/p\u003e\u003cp\u003eOnly if the number is positive, it is added to the sequence.\u003c/p\u003e\u003cp\u003eThe loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/p\u003e\u003cp\u003e\u003cb\u003eYou are not allowed to use the functions \u003ctt\u003esum()\u003c/tt\u003e and \u003ctt\u003emean()\u003c/tt\u003e\u003c/b\u003e\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 4, 3, 5, 10, 3, 0\r\nOutput is: 5\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 0\r\nOutput is 0\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\r\nOutput is: 4\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eNote\u003c/b\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\u003c/p\u003e","function_template":"function average = MeanWhile()\r\n    average = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'sum')),'sum() function is forbidden')\r\n\r\n%%\r\nfiletext = fileread('MeanWhile.m');\r\nassert(isempty(strfind(filetext, 'mean')),'mean() function is forbidden')\r\n\r\n%%\r\nrng(1);\r\nav_correct = 5.5;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(2);\r\nav_correct = 4;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(3);\r\nav_correct = 5.25;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(7);\r\nav_correct = 0;\r\nassert(isequal(MeanWhile(),av_correct))\r\n\r\n%%\r\nrng(0);\r\nav_correct = 6.571428571428571;\r\nassert(isequal(MeanWhile(),av_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":416,"test_suite_updated_at":"2017-12-17T07:32:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-16T22:37:19.000Z","updated_at":"2026-03-10T18:45:32.000Z","published_at":"2017-12-17T07:32:04.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that generates random integers within a loop, and calculates the mean of the positive numbers only.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt each iteration a random integer between 0 and 10 is generated.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnly if the number is positive, it is added to the sequence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe loop terminates when the number 0 is generated. This number is not considered for the mean.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eYou are not allowed to use the functions\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esum()\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emean()\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Random sequence is: 4, 3, 5, 10, 3, 0\\nOutput is: 5\\n\\nRandom sequence is: 0\\nOutput is 0\\n\\nRandom sequence is: 5, 8, 1, 9, 3, 4, 6, 2, 2, 3, 1, 0\\nOutput is: 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: the function does not have an input. The output depends on the state of the random numbers generator.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44457,"title":"Triangle of numbers","description":"Create a matrix with the integers from 1 to |n| arranged in a triangular shape.\r\n\r\nEvery row |i| of the matrix contains |i| integers, and the rest of the elements are zeros.\r\n\r\nExamples:\r\n\r\n  Input:  n = 6\r\n  Output: mat = [1 0 0\r\n                 2 3 0\r\n                 4 5 6]\r\n\r\n  Input:  n = 12\r\n  Output: mat = [1  0  0  0 \r\n                 2  3  0  0 \r\n                 4  5  6  0 \r\n                 7  8  9  10\r\n                 11 12 0  0]","description_html":"\u003cp\u003eCreate a matrix with the integers from 1 to \u003ctt\u003en\u003c/tt\u003e arranged in a triangular shape.\u003c/p\u003e\u003cp\u003eEvery row \u003ctt\u003ei\u003c/tt\u003e of the matrix contains \u003ctt\u003ei\u003c/tt\u003e integers, and the rest of the elements are zeros.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 6\r\nOutput: mat = [1 0 0\r\n               2 3 0\r\n               4 5 6]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput:  n = 12\r\nOutput: mat = [1  0  0  0 \r\n               2  3  0  0 \r\n               4  5  6  0 \r\n               7  8  9  10\r\n               11 12 0  0]\r\n\u003c/pre\u003e","function_template":"function mat = triangle(n)\r\n    mat = 1:n;\r\nend","test_suite":"%%\r\nfiletext = fileread('triangle.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\n\r\n%%\r\nn = 0;\r\nmat_correct = [];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 1;\r\nmat_correct = 1;\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 6;\r\nmat_correct = [1 0 0; 2 3 0; 4 5 6];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 12;\r\nmat_correct = [1 0 0 0; 2 3 0 0; 4 5 6 0; 7 8 9 10; 11 12 0 0];\r\nassert(isequal(triangle(n),mat_correct))\r\n\r\n%%\r\nn = 50;\r\nmat_correct = [1,zeros(1,8); 2:3,zeros(1,7); 4:6,zeros(1,6);\r\n    7:10,zeros(1,5); 11:15,zeros(1,4); 16:21,zeros(1,3);\r\n    22:28,0,0; ; 29:36,0; 37:45; 46:50,zeros(1,4)];\r\nassert(isequal(triangle(n),mat_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":674,"created_at":"2017-12-17T08:43:23.000Z","updated_at":"2026-02-11T20:05:28.000Z","published_at":"2017-12-17T08:43:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate a matrix with the integers from 1 to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e arranged in a triangular shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the matrix contains\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ei\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e integers, and the rest of the elements are zeros.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:  n = 6\\nOutput: mat = [1 0 0\\n               2 3 0\\n               4 5 6]\\n\\nInput:  n = 12\\nOutput: mat = [1  0  0  0 \\n               2  3  0  0 \\n               4  5  6  0 \\n               7  8  9  10\\n               11 12 0  0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":3074,"title":"Compute the cokurtosis of a given portfolio.","description":"As input data, you are given a nObs-by-nAssets matrix _portRet_ of return series for assets in a portfolio along with an nAssets-by-1 vector _portWeights_ of portfolio weights. Example: \r\n\r\n \u003e\u003e nObs = 504; % Number of observations\r\n\r\n \u003e\u003e nAssets = 5; % Number of assets in the portfolio\r\n\r\n \u003e\u003e portRet = randn(nObs, nAssets); % Sample portfolio return series\r\n\r\n \u003e\u003e portWeights = rand(nAssets, 1); \r\n\r\n \u003e\u003e portWeights = portWeights/sum(portWeights); % Portfolio weights are \u003e=0 and sum to 1.\r\n\r\nThe task is to compute the *portfolio cokurtosis* , which is a scalar statistic associated with the portfolio. A full description of this statistic, along with sample MATLAB code for computing it, can be found here:\r\n\r\nhttp://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\r\n\r\nWrite a function that accepts _portRet_ and _portWeights_ as input arguments and returns the scalar statistic _portCokurt_ as its output. You can use the code at the website above as a starting point, but try to simplify and shorten it in the spirit of Cody.\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eAs input data, you are given a nObs-by-nAssets matrix \u003ci\u003eportRet\u003c/i\u003e of return series for assets in a portfolio along with an nAssets-by-1 vector \u003ci\u003eportWeights\u003c/i\u003e of portfolio weights. Example:\u003c/p\u003e\u003cpre\u003e \u0026gt;\u0026gt; nObs = 504; % Number of observations\u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; nAssets = 5; % Number of assets in the portfolio\u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; portRet = randn(nObs, nAssets); % Sample portfolio return series\u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; portWeights = rand(nAssets, 1); \u003c/pre\u003e\u003cpre\u003e \u0026gt;\u0026gt; portWeights = portWeights/sum(portWeights); % Portfolio weights are \u0026gt;=0 and sum to 1.\u003c/pre\u003e\u003cp\u003eThe task is to compute the \u003cb\u003eportfolio cokurtosis\u003c/b\u003e , which is a scalar statistic associated with the portfolio. A full description of this statistic, along with sample MATLAB code for computing it, can be found here:\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\"\u003ehttp://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\u003c/a\u003e\u003c/p\u003e\u003cp\u003eWrite a function that accepts \u003ci\u003eportRet\u003c/i\u003e and \u003ci\u003eportWeights\u003c/i\u003e as input arguments and returns the scalar statistic \u003ci\u003eportCokurt\u003c/i\u003e as its output. You can use the code at the website above as a starting point, but try to simplify and shorten it in the spirit of Cody.\u003c/p\u003e","function_template":"function portCokurt = computePortCokurt(portRet, portWeights)\r\n\r\n\r\nend","test_suite":"%%\r\nrng('default')\r\nR = randn(504, 5);\r\nw = ones(5, 1)/5;\r\nassert(abs(computePortCokurt(R, w)-0.119749008958925)\u003c1e-3)\r\n\r\n%%\r\nrng('default')\r\nR = randn(252, 15);\r\nw = ones(15, 1)/15;\r\nassert(abs(computePortCokurt(R, w)-0.013012357540290)\u003c1e-3)\r\n\r\n%% \r\nrng('default')\r\nR = randn(100, 1);\r\nw = 1;\r\nassert(abs(computePortCokurt(R, w)-6.280759230562035)\u003c1e-3)\r\n\r\n%%\r\nrng('default')\r\nR = randn(5, 10);\r\nw = [0.1*ones(5, 1); 0.5; zeros(4, 1)];\r\nassert(abs(computePortCokurt(R, w)-0.169198885214440)\u003c1e-3)","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":2328,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-03-10T11:04:22.000Z","updated_at":"2015-03-11T18:00:35.000Z","published_at":"2015-03-10T11:25:35.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\u003eAs input data, you are given a nObs-by-nAssets matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportRet\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of return series for assets in a portfolio along with an nAssets-by-1 vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportWeights\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of portfolio weights. 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[ \u003e\u003e nObs = 504; % Number of observations\\n\\n \u003e\u003e nAssets = 5; % Number of assets in the portfolio\\n\\n \u003e\u003e portRet = randn(nObs, nAssets); % Sample portfolio return series\\n\\n \u003e\u003e portWeights = rand(nAssets, 1); \\n\\n \u003e\u003e portWeights = portWeights/sum(portWeights); % Portfolio weights are \u003e=0 and sum to 1.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe task is to compute the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportfolio cokurtosis\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , which is a scalar statistic associated with the portfolio. A full description of this statistic, along with sample MATLAB code for computing it, can be found here:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.quantatrisk.com/2013/01/20/coskewness-and-cokurtosis/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that accepts\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportRet\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportWeights\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as input arguments and returns the scalar statistic\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eportCokurt\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as its output. You can use the code at the website above as a starting point, but try to simplify and shorten it in the spirit of Cody.\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:\"loops\"","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:\"loops\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"loops\"","","\"","loops","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a60e8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fdbe93a6048\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a3d48\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a6908\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fdbe93a6868\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fdbe93a67c8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fdbe93a6188\u003e":"tag:\"loops\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a6188\u003e":"tag:\"loops\""},"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:\"loops\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"loops\"","","\"","loops","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a60e8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fdbe93a6048\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a3d48\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a6908\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fdbe93a6868\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fdbe93a67c8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fdbe93a6188\u003e":"tag:\"loops\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fdbe93a6188\u003e":"tag:\"loops\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":45394,"difficulty_rating":"easy-medium"},{"id":44901,"difficulty_rating":"easy-medium"},{"id":60791,"difficulty_rating":"easy-medium"},{"id":44454,"difficulty_rating":"easy-medium"},{"id":59721,"difficulty_rating":"easy-medium"},{"id":44468,"difficulty_rating":"easy-medium"},{"id":44469,"difficulty_rating":"easy-medium"},{"id":45395,"difficulty_rating":"medium"},{"id":44484,"difficulty_rating":"medium"},{"id":44455,"difficulty_rating":"medium"},{"id":44457,"difficulty_rating":"medium"},{"id":3074,"difficulty_rating":"unrated"}]}}