{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":45498,"title":"Trace the path of a harmful chemical in an ecological network","description":"An ecological network consists of the cycles of nature, such as the water cycle, the carbon cycle, the oxygen cycle, etc. Due to human activities, harmful chemicals (or persistent pollutants) are now entering these cycles and may stay there forever. Your job is to track a specific unknown chemical inside an ecological network.\r\n\r\nFor this problem, a network involves *N* _sites_ in nature, labelled as _Site_ 1, _Site_ 2, ..., _Site_ *N*. Researchers have identified an ecological network for you, which is given as a [1 x *N*] row vector called *P*. The network is read as follows: \"A chemical that enters _Site i_ always end up at _Site *P*(i)_\". Consider the following example:\r\n\r\n  If a chemical enters Site:      1 2 3 4 5\r\n     it will end up at Site: P = [3 1 5 2 4]\r\n  \r\nIf a harmful chemical enters the ecological network from _Site 2_, it will be traced to _Site 1_ (which is *P*(2)), then eventually at _Site 3_, then at _Site 5_, then at _Site 4_, then back to _Site 2_. Hence, the path of this chemical is [2 1 3 5 4].\r\n\r\nWrite a function that takes a vector *P* and a starting site *S*. Output the path of the chemical after it enters _Site *S*_ in the given ecological network. You are ensured that:\r\n\r\n* *P* is always a permutation of integers 1 to *N*.\r\n* 2 \u003c= *N* \u003c= 100\r\n* 1 \u003c= *S* \u003c= *N*\r\n\r\nSee sample test cases:\r\n\r\n  \u003e\u003e trace_chemical([3 1 5 2 4],2)\r\n     ans = \r\n         2 1 3 5 4\r\n\u003e\u003e trace_chemical([3 1 5 2 4],1)\r\n     ans =\r\n         1 3 5 4 2\r\n\u003e\u003e trace_chemical([4 1 6 5 2 3],1)\r\n     ans =\r\n         1 4 5 2","description_html":"\u003cp\u003eAn ecological network consists of the cycles of nature, such as the water cycle, the carbon cycle, the oxygen cycle, etc. Due to human activities, harmful chemicals (or persistent pollutants) are now entering these cycles and may stay there forever. Your job is to track a specific unknown chemical inside an ecological network.\u003c/p\u003e\u003cp\u003eFor this problem, a network involves \u003cb\u003eN\u003c/b\u003e \u003ci\u003esites\u003c/i\u003e in nature, labelled as \u003ci\u003eSite\u003c/i\u003e 1, \u003ci\u003eSite\u003c/i\u003e 2, ..., \u003ci\u003eSite\u003c/i\u003e \u003cb\u003eN\u003c/b\u003e. Researchers have identified an ecological network for you, which is given as a [1 x \u003cb\u003eN\u003c/b\u003e] row vector called \u003cb\u003eP\u003c/b\u003e. The network is read as follows: \"A chemical that enters \u003ci\u003eSite i\u003c/i\u003e always end up at \u003ci\u003eSite \u003cb\u003eP\u003c/b\u003e(i)\u003c/i\u003e\". Consider the following example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eIf a chemical enters Site:      1 2 3 4 5\r\n   it will end up at Site: P = [3 1 5 2 4]\r\n\u003c/pre\u003e\u003cp\u003eIf a harmful chemical enters the ecological network from \u003ci\u003eSite 2\u003c/i\u003e, it will be traced to \u003ci\u003eSite 1\u003c/i\u003e (which is \u003cb\u003eP\u003c/b\u003e(2)), then eventually at \u003ci\u003eSite 3\u003c/i\u003e, then at \u003ci\u003eSite 5\u003c/i\u003e, then at \u003ci\u003eSite 4\u003c/i\u003e, then back to \u003ci\u003eSite 2\u003c/i\u003e. Hence, the path of this chemical is [2 1 3 5 4].\u003c/p\u003e\u003cp\u003eWrite a function that takes a vector \u003cb\u003eP\u003c/b\u003e and a starting site \u003cb\u003eS\u003c/b\u003e. Output the path of the chemical after it enters \u003ci\u003eSite \u003cb\u003eS\u003c/b\u003e\u003c/i\u003e in the given ecological network. You are ensured that:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003eP\u003c/b\u003e is always a permutation of integers 1 to \u003cb\u003eN\u003c/b\u003e.\u003c/li\u003e\u003cli\u003e2 \u0026lt;= \u003cb\u003eN\u003c/b\u003e \u0026lt;= 100\u003c/li\u003e\u003cli\u003e1 \u0026lt;= \u003cb\u003eS\u003c/b\u003e \u0026lt;= \u003cb\u003eN\u003c/b\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSee sample test cases:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; trace_chemical([3 1 5 2 4],2)\r\n   ans = \r\n       2 1 3 5 4\r\n\u0026gt;\u0026gt; trace_chemical([3 1 5 2 4],1)\r\n   ans =\r\n       1 3 5 4 2\r\n\u0026gt;\u0026gt; trace_chemical([4 1 6 5 2 3],1)\r\n   ans =\r\n       1 4 5 2\r\n\u003c/pre\u003e","function_template":"function y = trace_chemical(P,S)\r\n  y = P;\r\nend","test_suite":"%%\r\nfiletext = fileread('trace_chemical.m')\r\nassert(isempty(strfind(filetext, 'rand')))\r\nassert(isempty(strfind(filetext, 'fileread')))\r\nassert(isempty(strfind(filetext, 'assert')))\r\nassert(isempty(strfind(filetext, 'echo')))\r\n%%\r\nP = [3 1 5 2 4];\r\nans = [2 1 3 5 4];\r\nassert(isequal(trace_chemical(P,2),ans))\r\n%%\r\nP = [3 1 5 2 4];\r\nans = [1 3 5 4 2];\r\nassert(isequal(trace_chemical(P,1),ans))\r\n%%\r\nP = [2 5 8 6 10 9 3 4 7 1 ];\r\nans = [8 4 6 9 7 3 ];\r\nassert(isequal(trace_chemical(P,8),ans))\r\n%%\r\nP = [36 15 70 23 1 60 35 13 19 41 48 20 49 44 68 29 9 61 51 38 ...\r\n     32 2 40 8 72 39 26 28 67 69 42 76 66 34 47 46 11 77 71 64 ...\r\n     4 37 80 18 74 52 7 33 58 50 27 3 45 55 65 43 21 54 31 6 ...\r\n     24 63 57 30 12 78 22 75 14 10 16 17 81 53 59 25 56 5 73 62 ...\r\n     79 ];\r\nans = [60 6 ];\r\nassert(isequal(trace_chemical(P,60),ans))\r\n%%\r\nP = [8 45 12 53 33 15 29 39 40 21 9 26 32 58 20 43 54 17 48 55 ...\r\n     5 49 37 57 16 46 36 10 34 6 38 50 11 27 22 42 19 4 13 47 ...\r\n     52 2 23 25 35 24 30 56 44 41 28 14 51 31 7 3 1 18 ];\r\nans = [35 22 49 44 25 16 43 23 37 19 48 56 3 12 26 46 24 57 1 8 ...\r\n     39 13 32 50 41 52 14 58 18 17 54 31 38 4 53 51 28 10 21 5 ...\r\n     33 11 9 40 47 30 6 15 20 55 7 29 34 27 36 42 2 45 ];\r\nassert(isequal(trace_chemical(P,35),ans))\r\n%%\r\nP = [9 28 7 42 18 16 30 17 24 20 41 29 13 15 44 8 27 23 12 19 ...\r\n     21 32 40 49 11 47 14 25 35 36 46 38 33 45 34 4 43 48 31 5 ...\r\n     3 10 26 39 37 1 22 6 2 ];\r\nans = [24 49 2 28 25 11 41 3 7 30 36 4 42 10 20 19 12 29 35 34 ...\r\n     45 37 43 26 47 22 32 38 48 6 16 8 17 27 14 15 44 39 31 46 ...\r\n     1 9 ];\r\nassert(isequal(trace_chemical(P,24),ans))\r\n%%\r\nP = [39 27 32 17 22 3 21 8 4 16 45 37 40 2 19 11 51 36 50 43 ...\r\n     13 44 12 30 48 28 42 35 10 14 5 38 15 9 20 18 6 26 31 24 ...\r\n     23 41 34 1 46 7 47 33 49 29 25 ];\r\nans = [11 45 46 7 21 13 40 24 30 14 2 27 42 41 23 12 37 6 3 32 ...\r\n     38 26 28 35 20 43 34 9 4 17 51 25 48 33 15 19 50 29 10 16 ];\r\nassert(isequal(trace_chemical(P,11),ans))\r\n%%\r\nP = [19 10 17 9 18 7 13 14 20 21 5 3 6 16 8 12 15 11 2 4 1];\r\nans = [4 9 20 ];\r\nassert(isequal(trace_chemical(P,4),ans))\r\n%%\r\nP = [12 1 5 66 26 29 64 68 2 33 38 41 55 8 18 49 27 47 22 50 ...\r\n     35 24 16 13 60 34 46 36 6 56 67 30 42 48 19 37 63 57 11 17 ...\r\n     40 59 15 23 45 32 61 44 53 31 28 10 62 9 21 7 52 14 39 51 ...\r\n     58 65 54 43 3 4 20 25 ];\r\nans = [26 34 48 44 23 16 49 53 62 65 3 5 ];\r\nassert(isequal(trace_chemical(P,26),ans))\r\n%%\r\nP = [65 8 29 66 49 72 61 38 18 33 58 62 67 40 20 27 46 1 5 6 ...\r\n     14 75 82 74 23 37 54 22 78 41 4 53 13 47 57 51 17 69 77 71 ...\r\n     64 35 25 44 21 70 19 76 36 10 81 42 60 79 28 31 9 48 3 56 ...\r\n     24 59 11 50 7 26 30 16 52 39 15 2 68 73 34 80 32 12 63 55 ...\r\n     45 43 ];\r\nans = [17 46 70 39 77 32 53 60 56 31 4 66 26 37 ];\r\nassert(isequal(trace_chemical(P,17),ans))\r\n%%\r\nP = [1 17 15 6 13 33 28 36 4 22 44 23 32 40 26 12 41 30 8 34 ...\r\n     37 14 21 5 9 10 29 3 35 38 11 43 31 16 19 27 24 45 39 7 ...\r\n     2 42 20 18 25 ];\r\nans = [14 40 7 28 3 15 26 10 22 ];\r\nassert(isequal(trace_chemical(P,14),ans))\r\n%%\r\nP = [1 17 21 15 6 24 13 5 4 18 2 9 3 29 10 28 12 23 11 25 ...\r\n     20 19 8 16 27 26 7 22 14 ];\r\nans = [10 18 23 8 5 6 24 16 28 22 19 11 2 17 12 9 4 15 ];\r\nassert(isequal(trace_chemical(P,10),ans))\r\n%%\r\nP = [6 2 3 4 1 7 5 ];\r\nans = [3 ];\r\nassert(isequal(trace_chemical(P,3),ans))\r\n%%\r\nP = [11 19 15 23 14 10 3 4 25 7 24 1 18 26 6 16 17 20 12 2 ...\r\n     13 22 9 21 8 5 ];\r\nans = [16 ];\r\nassert(isequal(trace_chemical(P,16),ans))\r\n%%\r\nP = [20 16 5 9 30 28 8 24 14 15 23 4 29 11 22 19 26 17 25 6 ...\r\n     27 18 3 2 1 13 31 12 10 21 7 ];\r\nans = [11 23 3 5 30 21 27 31 7 8 24 2 16 19 25 1 20 6 28 12 ...\r\n     4 9 14 ];\r\nassert(isequal(trace_chemical(P,11),ans))\r\n%%\r\nP = [1 18 16 8 15 21 27 22 23 17 26 19 3 4 9 11 7 6 29 2 ...\r\n     12 25 24 5 14 28 20 10 13 ];\r\nans = [22 25 14 4 8 ];\r\nassert(isequal(trace_chemical(P,22),ans))\r\n%%\r\nP = [38 48 42 87 57 89 92 12 20 62 59 51 26 29 45 55 10 71 44 69 ...\r\n     34 60 30 77 53 11 54 14 23 15 22 43 49 13 41 5 47 91 68 37 ...\r\n     9 3 76 31 85 33 40 1 63 70 18 8 17 35 90 36 24 83 94 21 ...\r\n     73 27 61 78 39 82 64 93 66 6 67 84 56 80 19 50 95 2 75 46 ...\r\n     74 16 81 72 4 25 86 32 28 52 65 58 88 7 79 ];\r\nans = [54 35 41 9 20 69 66 82 16 55 90 52 8 12 51 18 71 67 64 78 ...\r\n     2 48 1 38 91 65 39 68 93 88 32 43 76 50 70 6 89 28 14 29 ...\r\n     23 30 15 45 85 4 87 86 25 53 17 10 62 27 ];\r\nassert(isequal(trace_chemical(P,54),ans))\r\n%%\r\nP = [69 48 11 21 80 50 75 64 41 54 23 82 61 45 25 10 74 63 72 8 ...\r\n     15 81 42 60 59 65 35 37 70 33 76 24 36 49 56 18 38 6 44 39 ...\r\n     4 17 52 51 32 43 1 46 55 73 34 28 58 31 68 29 67 22 66 12 ...\r\n     53 5 16 77 19 7 13 26 57 79 3 47 71 40 14 30 2 20 62 9 ...\r\n     78 27 ];\r\nans = [27 35 56 29 70 79 62 5 80 9 41 4 21 15 25 59 66 7 75 14 ...\r\n     45 32 24 60 12 82 ];\r\nassert(isequal(trace_chemical(P,27),ans))\r\n%%\r\nP = [78 59 84 70 19 82 34 69 29 92 6 51 52 28 10 32 31 33 4 73 ...\r\n     24 89 99 68 64 47 46 95 94 21 53 44 62 26 93 91 58 55 98 79 ...\r\n     11 35 48 40 22 66 87 80 63 43 12 97 13 17 67 20 1 85 60 81 ...\r\n     25 50 88 49 96 90 76 83 36 15 75 23 41 86 39 9 8 54 7 61 ...\r\n     2 72 45 38 16 71 56 37 3 14 27 74 5 57 65 18 42 30 77 ];\r\nans = [85 16 32 44 40 79 7 34 26 47 87 56 20 73 41 11 6 82 72 23 ...\r\n     99 77 8 69 36 91 27 46 66 90 14 28 95 65 96 18 33 62 50 43 ...\r\n     48 80 61 25 64 49 63 88 37 58 ];\r\nassert(isequal(trace_chemical(P,85),ans))\r\n%%\r\nP = [86 17 25 63 38 72 9 64 56 10 7 26 43 28 36 40 24 71 41 22 ...\r\n     27 80 21 1 54 84 42 11 60 73 6 46 78 50 67 66 20 23 77 74 ...\r\n     57 44 85 75 16 13 47 14 29 48 19 58 2 39 81 83 59 33 49 61 ...\r\n     69 53 3 35 8 55 32 18 31 30 12 51 34 65 87 62 5 52 15 45 ...\r\n     4 68 82 76 70 37 79 ];\r\nans = [36 66 55 81 4 63 3 25 54 39 77 5 38 23 21 27 42 44 75 87 ...\r\n     79 15 ];\r\nassert(isequal(trace_chemical(P,36),ans))\r\n%%\r\nP = [25 7 4 6 16 30 24 28 9 3 31 13 10 23 2 26 29 8 5 20 ...\r\n     18 27 21 11 22 17 12 19 1 15 14 ];\r\nans = [21 18 8 28 19 5 16 26 17 29 1 25 22 27 12 13 10 3 4 6 ...\r\n     30 15 2 7 24 11 31 14 23 ];\r\nassert(isequal(trace_chemical(P,21),ans))\r\n%%\r\nP = [30 31 13 37 59 49 28 25 65 61 22 8 43 80 64 18 2 74 46 14 ...\r\n     85 12 62 5 55 67 48 42 78 83 47 15 79 89 34 68 54 90 3 44 ...\r\n     72 40 21 24 60 82 35 50 66 11 41 77 75 7 16 27 73 10 76 71 ...\r\n     33 56 39 53 38 19 36 84 69 81 23 87 9 51 70 86 88 1 26 57 ...\r\n     63 20 4 52 29 45 58 6 17 32 ];\r\nans = [78 1 30 83 4 37 54 7 28 42 40 44 24 5 59 76 86 45 60 71 ...\r\n     23 62 56 27 48 50 11 22 12 8 25 55 16 18 74 51 41 72 87 58 ...\r\n     10 61 33 79 26 67 36 68 84 52 77 88 6 49 66 19 46 82 20 14 ...\r\n     80 57 73 9 65 38 90 32 15 64 53 75 70 81 63 39 3 13 43 21 ...\r\n     85 29 ];\r\nassert(isequal(trace_chemical(P,78),ans))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2020-05-07T02:09:17.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-06T19:35:57.000Z","updated_at":"2025-12-07T16:54:53.000Z","published_at":"2020-05-06T19:53:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn ecological network consists of the cycles of nature, such as the water cycle, the carbon cycle, the oxygen cycle, etc. Due to human activities, harmful chemicals (or persistent pollutants) are now entering these cycles and may stay there forever. Your job is to track a specific unknown chemical inside an ecological network.\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, a network involves\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\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esites\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in nature, labelled as\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\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 1,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 2, ...,\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\u003eSite\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Researchers have identified an ecological network for you, which is given as a [1 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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e] row vector called\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\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The network is read as follows: \\\"A chemical that enters\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\u003eSite i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e always end up at\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\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e(i)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e\\\". Consider the following 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[If a chemical enters Site:      1 2 3 4 5\\n   it will end up at Site: P = [3 1 5 2 4]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a harmful chemical enters the ecological network from\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\u003eSite 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, it will be traced 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSite 1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (which is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(2)), then eventually at\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\u003eSite 3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then at\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\u003eSite 5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then at\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\u003eSite 4\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then back 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSite 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Hence, the path of this chemical is [2 1 3 5 4].\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 takes a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a starting site\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\u003eS\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Output the path of the chemical after it enters\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\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eS\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the given ecological network. You are 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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is always a permutation of integers 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:b/\u003e\u003c/w:rPr\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2 \u0026lt;=\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026lt;= 100\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;=\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\u003eS\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026lt;=\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee sample test cases:\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 trace_chemical([3 1 5 2 4],2)\\n   ans = \\n       2 1 3 5 4\\n\u003e\u003e trace_chemical([3 1 5 2 4],1)\\n   ans =\\n       1 3 5 4 2\\n\u003e\u003e trace_chemical([4 1 6 5 2 3],1)\\n   ans =\\n       1 4 5 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1649,"title":"Magic - Faro Shuffle","description":"The Faro shuffle is the perfect interweaving of cards.  Quiz: How many Faro's returns a standard 52 deck to its start?  Fifty four cards require 52 shuffles while 64 cards requires only 6 shuffles.\r\n\r\nThis challenge is to return the vectors of shuffle results until the original sequence is re-created.\r\n\r\n*Input:* N  (number of cards-even; start sequence 1:N)\r\n\r\n*Output:* deck (Array of cards created by the Faro shuffles)\r\n\r\nExample: N=4, deck= [1 3 2 4;1 2 3 4]\r\n\r\nN=8, deck=[1 5 2 6 3 7 4 8;1 3 5 7 2 4 6 8;1 2 3 4 5 6 7 8 ] \r\n\r\n*Code Exclusions:* regexp, str2num  (enforced if necessary)\r\n","description_html":"\u003cp\u003eThe Faro shuffle is the perfect interweaving of cards.  Quiz: How many Faro's returns a standard 52 deck to its start?  Fifty four cards require 52 shuffles while 64 cards requires only 6 shuffles.\u003c/p\u003e\u003cp\u003eThis challenge is to return the vectors of shuffle results until the original sequence is re-created.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e N  (number of cards-even; start sequence 1:N)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e deck (Array of cards created by the Faro shuffles)\u003c/p\u003e\u003cp\u003eExample: N=4, deck= [1 3 2 4;1 2 3 4]\u003c/p\u003e\u003cp\u003eN=8, deck=[1 5 2 6 3 7 4 8;1 3 5 7 2 4 6 8;1 2 3 4 5 6 7 8 ]\u003c/p\u003e\u003cp\u003e\u003cb\u003eCode Exclusions:\u003c/b\u003e regexp, str2num  (enforced if necessary)\u003c/p\u003e","function_template":"function deck = Faro(n)\r\n  deck=1:n;\r\nend","test_suite":"%%\r\nn=52; % Quiz answer : Takes 8 Faro Shuffles\r\ndeck = Faro(n);\r\ndeck_exp=[1 27 2 28 3 29 4 30 5 31 6 32 7 33 8 34 9 35 10 36 11 37 12 38 13 39 14 40 15 41 16 42 17 43 18 44 19 45 20 46 21 47 22 48 23 49 24 50 25 51 26 52 \r\n1 14 27 40 2 15 28 41 3 16 29 42 4 17 30 43 5 18 31 44 6 19 32 45 7 20 33 46 8 21 34 47 9 22 35 48 10 23 36 49 11 24 37 50 12 25 38 51 13 26 39 52 \r\n1 33 14 46 27 8 40 21 2 34 15 47 28 9 41 22 3 35 16 48 29 10 42 23 4 36 17 49 30 11 43 24 5 37 18 50 31 12 44 25 6 38 19 51 32 13 45 26 7 39 20 52 \r\n1 17 33 49 14 30 46 11 27 43 8 24 40 5 21 37 2 18 34 50 15 31 47 12 28 44 9 25 41 6 22 38 3 19 35 51 16 32 48 13 29 45 10 26 42 7 23 39 4 20 36 52 \r\n1 9 17 25 33 41 49 6 14 22 30 38 46 3 11 19 27 35 43 51 8 16 24 32 40 48 5 13 21 29 37 45 2 10 18 26 34 42 50 7 15 23 31 39 47 4 12 20 28 36 44 52 \r\n1 5 9 13 17 21 25 29 33 37 41 45 49 2 6 10 14 18 22 26 30 34 38 42 46 50 3 7 11 15 19 23 27 31 35 39 43 47 51 4 8 12 16 20 24 28 32 36 40 44 48 52 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=16;\r\ndeck = Faro(n);\r\ndeck_exp=[1 9 2 10 3 11 4 12 5 13 6 14 7 15 8 16 \r\n1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16 \r\n1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 16 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=32;\r\ndeck = Faro(n);\r\ndeck_exp=[1 17 2 18 3 19 4 20 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 32 \r\n1 9 17 25 2 10 18 26 3 11 19 27 4 12 20 28 5 13 21 29 6 14 22 30 7 15 23 31 8 16 24 32 \r\n1 5 9 13 17 21 25 29 2 6 10 14 18 22 26 30 3 7 11 15 19 23 27 31 4 8 12 16 20 24 28 32 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=64;\r\ndeck = Faro(n);\r\ndeck_exp=[1 33 2 34 3 35 4 36 5 37 6 38 7 39 8 40 9 41 10 42 11 43 12 44 13 45 14 46 15 47 16 48 17 49 18 50 19 51 20 52 21 53 22 54 23 55 24 56 25 57 26 58 27 59 28 60 29 61 30 62 31 63 32 64 \r\n1 17 33 49 2 18 34 50 3 19 35 51 4 20 36 52 5 21 37 53 6 22 38 54 7 23 39 55 8 24 40 56 9 25 41 57 10 26 42 58 11 27 43 59 12 28 44 60 13 29 45 61 14 30 46 62 15 31 47 63 16 32 48 64 \r\n1 9 17 25 33 41 49 57 2 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 \r\n1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 ];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=54;\r\ndeck = Faro(n);\r\ndeck_exp=[1 28 2 29 3 30 4 31 5 32 6 33 7 34 8 35 9 36 10 37 11 38 12 39 13 40 14 41 15 42 16 43 17 44 18 45 19 46 20 47 21 48 22 49 23 50 24 51 25 52 26 53 27 54 \r\n1 41 28 15 2 42 29 16 3 43 30 17 4 44 31 18 5 45 32 19 6 46 33 20 7 47 34 21 8 48 35 22 9 49 36 23 10 50 37 24 11 51 38 25 12 52 39 26 13 53 40 27 14 54 \r\n1 21 41 8 28 48 15 35 2 22 42 9 29 49 16 36 3 23 43 10 30 50 17 37 4 24 44 11 31 51 18 38 5 25 45 12 32 52 19 39 6 26 46 13 33 53 20 40 7 27 47 14 34 54 \r\n1 11 21 31 41 51 8 18 28 38 48 5 15 25 35 45 2 12 22 32 42 52 9 19 29 39 49 6 16 26 36 46 3 13 23 33 43 53 10 20 30 40 50 7 17 27 37 47 4 14 24 34 44 54 \r\n1 6 11 16 21 26 31 36 41 46 51 3 8 13 18 23 28 33 38 43 48 53 5 10 15 20 25 30 35 40 45 50 2 7 12 17 22 27 32 37 42 47 52 4 9 14 19 24 29 34 39 44 49 54 \r\n1 30 6 35 11 40 16 45 21 50 26 2 31 7 36 12 41 17 46 22 51 27 3 32 8 37 13 42 18 47 23 52 28 4 33 9 38 14 43 19 48 24 53 29 5 34 10 39 15 44 20 49 25 54 \r\n1 42 30 18 6 47 35 23 11 52 40 28 16 4 45 33 21 9 50 38 26 14 2 43 31 19 7 48 36 24 12 53 41 29 17 5 46 34 22 10 51 39 27 15 3 44 32 20 8 49 37 25 13 54 \r\n1 48 42 36 30 24 18 12 6 53 47 41 35 29 23 17 11 5 52 46 40 34 28 22 16 10 4 51 45 39 33 27 21 15 9 3 50 44 38 32 26 20 14 8 2 49 43 37 31 25 19 13 7 54 \r\n1 51 48 45 42 39 36 33 30 27 24 21 18 15 12 9 6 3 53 50 47 44 41 38 35 32 29 26 23 20 17 14 11 8 5 2 52 49 46 43 40 37 34 31 28 25 22 19 16 13 10 7 4 54 \r\n1 26 51 23 48 20 45 17 42 14 39 11 36 8 33 5 30 2 27 52 24 49 21 46 18 43 15 40 12 37 9 34 6 31 3 28 53 25 50 22 47 19 44 16 41 13 38 10 35 7 32 4 29 54 \r\n1 40 26 12 51 37 23 9 48 34 20 6 45 31 17 3 42 28 14 53 39 25 11 50 36 22 8 47 33 19 5 44 30 16 2 41 27 13 52 38 24 10 49 35 21 7 46 32 18 4 43 29 15 54 \r\n1 47 40 33 26 19 12 5 51 44 37 30 23 16 9 2 48 41 34 27 20 13 6 52 45 38 31 24 17 10 3 49 42 35 28 21 14 7 53 46 39 32 25 18 11 4 50 43 36 29 22 15 8 54 \r\n1 24 47 17 40 10 33 3 26 49 19 42 12 35 5 28 51 21 44 14 37 7 30 53 23 46 16 39 9 32 2 25 48 18 41 11 34 4 27 50 20 43 13 36 6 29 52 22 45 15 38 8 31 54 \r\n1 39 24 9 47 32 17 2 40 25 10 48 33 18 3 41 26 11 49 34 19 4 42 27 12 50 35 20 5 43 28 13 51 36 21 6 44 29 14 52 37 22 7 45 30 15 53 38 23 8 46 31 16 54 \r\n1 20 39 5 24 43 9 28 47 13 32 51 17 36 2 21 40 6 25 44 10 29 48 14 33 52 18 37 3 22 41 7 26 45 11 30 49 15 34 53 19 38 4 23 42 8 27 46 12 31 50 16 35 54 \r\n1 37 20 3 39 22 5 41 24 7 43 26 9 45 28 11 47 30 13 49 32 15 51 34 17 53 36 19 2 38 21 4 40 23 6 42 25 8 44 27 10 46 29 12 48 31 14 50 33 16 52 35 18 54 \r\n1 19 37 2 20 38 3 21 39 4 22 40 5 23 41 6 24 42 7 25 43 8 26 44 9 27 45 10 28 46 11 29 47 12 30 48 13 31 49 14 32 50 15 33 51 16 34 52 17 35 53 18 36 54 \r\n1 10 19 28 37 46 2 11 20 29 38 47 3 12 21 30 39 48 4 13 22 31 40 49 5 14 23 32 41 50 6 15 24 33 42 51 7 16 25 34 43 52 8 17 26 35 44 53 9 18 27 36 45 54 \r\n1 32 10 41 19 50 28 6 37 15 46 24 2 33 11 42 20 51 29 7 38 16 47 25 3 34 12 43 21 52 30 8 39 17 48 26 4 35 13 44 22 53 31 9 40 18 49 27 5 36 14 45 23 54 \r\n1 43 32 21 10 52 41 30 19 8 50 39 28 17 6 48 37 26 15 4 46 35 24 13 2 44 33 22 11 53 42 31 20 9 51 40 29 18 7 49 38 27 16 5 47 36 25 14 3 45 34 23 12 54 \r\n1 22 43 11 32 53 21 42 10 31 52 20 41 9 30 51 19 40 8 29 50 18 39 7 28 49 17 38 6 27 48 16 37 5 26 47 15 36 4 25 46 14 35 3 24 45 13 34 2 23 44 12 33 54 \r\n1 38 22 6 43 27 11 48 32 16 53 37 21 5 42 26 10 47 31 15 52 36 20 4 41 25 9 46 30 14 51 35 19 3 40 24 8 45 29 13 50 34 18 2 39 23 7 44 28 12 49 33 17 54 \r\n1 46 38 30 22 14 6 51 43 35 27 19 11 3 48 40 32 24 16 8 53 45 37 29 21 13 5 50 42 34 26 18 10 2 47 39 31 23 15 7 52 44 36 28 20 12 4 49 41 33 25 17 9 54 \r\n1 50 46 42 38 34 30 26 22 18 14 10 6 2 51 47 43 39 35 31 27 23 19 15 11 7 3 52 48 44 40 36 32 28 24 20 16 12 8 4 53 49 45 41 37 33 29 25 21 17 13 9 5 54 \r\n1 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 54 \r\n1 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 54 \r\n1 27 53 26 52 25 51 24 50 23 49 22 48 21 47 20 46 19 45 18 44 17 43 16 42 15 41 14 40 13 39 12 38 11 37 10 36 9 35 8 34 7 33 6 32 5 31 4 30 3 29 2 28 54 \r\n1 14 27 40 53 13 26 39 52 12 25 38 51 11 24 37 50 10 23 36 49 9 22 35 48 8 21 34 47 7 20 33 46 6 19 32 45 5 18 31 44 4 17 30 43 3 16 29 42 2 15 28 41 54 \r\n1 34 14 47 27 7 40 20 53 33 13 46 26 6 39 19 52 32 12 45 25 5 38 18 51 31 11 44 24 4 37 17 50 30 10 43 23 3 36 16 49 29 9 42 22 2 35 15 48 28 8 41 21 54 \r\n1 44 34 24 14 4 47 37 27 17 7 50 40 30 20 10 53 43 33 23 13 3 46 36 26 16 6 49 39 29 19 9 52 42 32 22 12 2 45 35 25 15 5 48 38 28 18 8 51 41 31 21 11 54 \r\n1 49 44 39 34 29 24 19 14 9 4 52 47 42 37 32 27 22 17 12 7 2 50 45 40 35 30 25 20 15 10 5 53 48 43 38 33 28 23 18 13 8 3 51 46 41 36 31 26 21 16 11 6 54 \r\n1 25 49 20 44 15 39 10 34 5 29 53 24 48 19 43 14 38 9 33 4 28 52 23 47 18 42 13 37 8 32 3 27 51 22 46 17 41 12 36 7 31 2 26 50 21 45 16 40 11 35 6 30 54 \r\n1 13 25 37 49 8 20 32 44 3 15 27 39 51 10 22 34 46 5 17 29 41 53 12 24 36 48 7 19 31 43 2 14 26 38 50 9 21 33 45 4 16 28 40 52 11 23 35 47 6 18 30 42 54 \r\n1 7 13 19 25 31 37 43 49 2 8 14 20 26 32 38 44 50 3 9 15 21 27 33 39 45 51 4 10 16 22 28 34 40 46 52 5 11 17 23 29 35 41 47 53 6 12 18 24 30 36 42 48 54 \r\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 \r\n1 29 4 32 7 35 10 38 13 41 16 44 19 47 22 50 25 53 28 3 31 6 34 9 37 12 40 15 43 18 46 21 49 24 52 27 2 30 5 33 8 36 11 39 14 42 17 45 20 48 23 51 26 54 \r\n1 15 29 43 4 18 32 46 7 21 35 49 10 24 38 52 13 27 41 2 16 30 44 5 19 33 47 8 22 36 50 11 25 39 53 14 28 42 3 17 31 45 6 20 34 48 9 23 37 51 12 26 40 54 \r\n1 8 15 22 29 36 43 50 4 11 18 25 32 39 46 53 7 14 21 28 35 42 49 3 10 17 24 31 38 45 52 6 13 20 27 34 41 48 2 9 16 23 30 37 44 51 5 12 19 26 33 40 47 54 \r\n1 31 8 38 15 45 22 52 29 6 36 13 43 20 50 27 4 34 11 41 18 48 25 2 32 9 39 16 46 23 53 30 7 37 14 44 21 51 28 5 35 12 42 19 49 26 3 33 10 40 17 47 24 54 \r\n1 16 31 46 8 23 38 53 15 30 45 7 22 37 52 14 29 44 6 21 36 51 13 28 43 5 20 35 50 12 27 42 4 19 34 49 11 26 41 3 18 33 48 10 25 40 2 17 32 47 9 24 39 54 \r\n1 35 16 50 31 12 46 27 8 42 23 4 38 19 53 34 15 49 30 11 45 26 7 41 22 3 37 18 52 33 14 48 29 10 44 25 6 40 21 2 36 17 51 32 13 47 28 9 43 24 5 39 20 54 \r\n1 18 35 52 16 33 50 14 31 48 12 29 46 10 27 44 8 25 42 6 23 40 4 21 38 2 19 36 53 17 34 51 15 32 49 13 30 47 11 28 45 9 26 43 7 24 41 5 22 39 3 20 37 54 \r\n1 36 18 53 35 17 52 34 16 51 33 15 50 32 14 49 31 13 48 30 12 47 29 11 46 28 10 45 27 9 44 26 8 43 25 7 42 24 6 41 23 5 40 22 4 39 21 3 38 20 2 37 19 54 \r\n1 45 36 27 18 9 53 44 35 26 17 8 52 43 34 25 16 7 51 42 33 24 15 6 50 41 32 23 14 5 49 40 31 22 13 4 48 39 30 21 12 3 47 38 29 20 11 2 46 37 28 19 10 54 \r\n1 23 45 14 36 5 27 49 18 40 9 31 53 22 44 13 35 4 26 48 17 39 8 30 52 21 43 12 34 3 25 47 16 38 7 29 51 20 42 11 33 2 24 46 15 37 6 28 50 19 41 10 32 54 \r\n1 12 23 34 45 3 14 25 36 47 5 16 27 38 49 7 18 29 40 51 9 20 31 42 53 11 22 33 44 2 13 24 35 46 4 15 26 37 48 6 17 28 39 50 8 19 30 41 52 10 21 32 43 54 \r\n1 33 12 44 23 2 34 13 45 24 3 35 14 46 25 4 36 15 47 26 5 37 16 48 27 6 38 17 49 28 7 39 18 50 29 8 40 19 51 30 9 41 20 52 31 10 42 21 53 32 11 43 22 54 \r\n1 17 33 49 12 28 44 7 23 39 2 18 34 50 13 29 45 8 24 40 3 19 35 51 14 30 46 9 25 41 4 20 36 52 15 31 47 10 26 42 5 21 37 53 16 32 48 11 27 43 6 22 38 54 \r\n1 9 17 25 33 41 49 4 12 20 28 36 44 52 7 15 23 31 39 47 2 10 18 26 34 42 50 5 13 21 29 37 45 53 8 16 24 32 40 48 3 11 19 27 35 43 51 6 14 22 30 38 46 54 \r\n1 5 9 13 17 21 25 29 33 37 41 45 49 53 4 8 12 16 20 24 28 32 36 40 44 48 52 3 7 11 15 19 23 27 31 35 39 43 47 51 2 6 10 14 18 22 26 30 34 38 42 46 50 54 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 ];\r\nassert(isequal(deck,deck_exp))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-14T22:13:26.000Z","updated_at":"2026-03-16T12:10:09.000Z","published_at":"2013-06-14T22:50:57.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 Faro shuffle is the perfect interweaving of cards. Quiz: How many Faro's returns a standard 52 deck to its start? Fifty four cards require 52 shuffles while 64 cards requires only 6 shuffles.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis challenge is to return the vectors of shuffle results until the original sequence is re-created.\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\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e N (number of cards-even; start sequence 1: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e deck (Array of cards created by the Faro shuffles)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: N=4, deck= [1 3 2 4;1 2 3 4]\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\u003eN=8, deck=[1 5 2 6 3 7 4 8;1 3 5 7 2 4 6 8;1 2 3 4 5 6 7 8 ]\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\u003eCode Exclusions:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e regexp, str2num (enforced if necessary)\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":45193,"title":"Fun with permutations","description":"There are factorial(N) permutations of the numbers from 1 to N. For each of these permutations, we can find the set of indexes j that will return the numbers to their original order, 1:N.  For example, if we generate a random permutation p with p = randperm(1:N) then the set of indices j that will return p to the original order\r\np(j) = 1:N may be found by [~,j] = sort(p).\r\n\r\nIt sometimes happens that this set of indices j and the corresponding permutation p are the same.  For example, if p = 1:N, then j = 1:N as well; and if p = N:-1:1, then\r\nj is also N:-1:1.  However, for N = 3, there are 6 permutations in all, and it happens that only 4 of them have this property.  \r\n\r\nYour task is to determine, given the value of N, the number of permutations p of the array 1:N for which the permutation p and the indexes j are the same.\r\n\r\ninput: N, the range of the integers,\r\noutput: The number of permutations of 1:N for which isequal(p,j)\r\n\r\nHINT: For N \u003c 12, you can probably solve this by checking each of the individual permutations, but for larger N this may prove to be too time-consuming.","description_html":"\u003cp\u003eThere are factorial(N) permutations of the numbers from 1 to N. For each of these permutations, we can find the set of indexes j that will return the numbers to their original order, 1:N.  For example, if we generate a random permutation p with p = randperm(1:N) then the set of indices j that will return p to the original order\r\np(j) = 1:N may be found by [~,j] = sort(p).\u003c/p\u003e\u003cp\u003eIt sometimes happens that this set of indices j and the corresponding permutation p are the same.  For example, if p = 1:N, then j = 1:N as well; and if p = N:-1:1, then\r\nj is also N:-1:1.  However, for N = 3, there are 6 permutations in all, and it happens that only 4 of them have this property.\u003c/p\u003e\u003cp\u003eYour task is to determine, given the value of N, the number of permutations p of the array 1:N for which the permutation p and the indexes j are the same.\u003c/p\u003e\u003cp\u003einput: N, the range of the integers,\r\noutput: The number of permutations of 1:N for which isequal(p,j)\u003c/p\u003e\u003cp\u003eHINT: For N \u0026lt; 12, you can probably solve this by checking each of the individual permutations, but for larger N this may prove to be too time-consuming.\u003c/p\u003e","function_template":"function y = funWithPerms(N)\r\n  y = N;\r\nend","test_suite":"%%\r\nN = 4;\r\ny_correct = 10;\r\nassert(funWithPerms(N) == y_correct);\r\n%%\r\nN = 6;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 38);\r\n%%\r\nN = 8;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 382);\r\n%%\r\nN = 10;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 2374);\r\n%%\r\nN = 12;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 35038);\r\n%%\r\nN = 14;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 298810);\r\n%%\r\nN = 16;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 5775842);\r\n%%\r\nN = 18;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 62332114);\r\n%%\r\nN = 20;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 1484916506);\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":8580,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-11-03T23:25:57.000Z","updated_at":"2025-11-06T15:52:17.000Z","published_at":"2019-11-03T23:41:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are factorial(N) permutations of the numbers from 1 to N. For each of these permutations, we can find the set of indexes j that will return the numbers to their original order, 1:N. For example, if we generate a random permutation p with p = randperm(1:N) then the set of indices j that will return p to the original order p(j) = 1:N may be found by [~,j] = sort(p).\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\u003eIt sometimes happens that this set of indices j and the corresponding permutation p are the same. For example, if p = 1:N, then j = 1:N as well; and if p = N:-1:1, then j is also N:-1:1. However, for N = 3, there are 6 permutations in all, and it happens that only 4 of them have this property.\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\u003eYour task is to determine, given the value of N, the number of permutations p of the array 1:N for which the permutation p and the indexes j are the same.\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\u003einput: N, the range of the integers, output: The number of permutations of 1:N for which isequal(p,j)\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\u003eHINT: For N \u0026lt; 12, you can probably solve this by checking each of the individual permutations, but for larger N this may prove to be too time-consuming.\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":45498,"title":"Trace the path of a harmful chemical in an ecological network","description":"An ecological network consists of the cycles of nature, such as the water cycle, the carbon cycle, the oxygen cycle, etc. Due to human activities, harmful chemicals (or persistent pollutants) are now entering these cycles and may stay there forever. Your job is to track a specific unknown chemical inside an ecological network.\r\n\r\nFor this problem, a network involves *N* _sites_ in nature, labelled as _Site_ 1, _Site_ 2, ..., _Site_ *N*. Researchers have identified an ecological network for you, which is given as a [1 x *N*] row vector called *P*. The network is read as follows: \"A chemical that enters _Site i_ always end up at _Site *P*(i)_\". Consider the following example:\r\n\r\n  If a chemical enters Site:      1 2 3 4 5\r\n     it will end up at Site: P = [3 1 5 2 4]\r\n  \r\nIf a harmful chemical enters the ecological network from _Site 2_, it will be traced to _Site 1_ (which is *P*(2)), then eventually at _Site 3_, then at _Site 5_, then at _Site 4_, then back to _Site 2_. Hence, the path of this chemical is [2 1 3 5 4].\r\n\r\nWrite a function that takes a vector *P* and a starting site *S*. Output the path of the chemical after it enters _Site *S*_ in the given ecological network. You are ensured that:\r\n\r\n* *P* is always a permutation of integers 1 to *N*.\r\n* 2 \u003c= *N* \u003c= 100\r\n* 1 \u003c= *S* \u003c= *N*\r\n\r\nSee sample test cases:\r\n\r\n  \u003e\u003e trace_chemical([3 1 5 2 4],2)\r\n     ans = \r\n         2 1 3 5 4\r\n\u003e\u003e trace_chemical([3 1 5 2 4],1)\r\n     ans =\r\n         1 3 5 4 2\r\n\u003e\u003e trace_chemical([4 1 6 5 2 3],1)\r\n     ans =\r\n         1 4 5 2","description_html":"\u003cp\u003eAn ecological network consists of the cycles of nature, such as the water cycle, the carbon cycle, the oxygen cycle, etc. Due to human activities, harmful chemicals (or persistent pollutants) are now entering these cycles and may stay there forever. Your job is to track a specific unknown chemical inside an ecological network.\u003c/p\u003e\u003cp\u003eFor this problem, a network involves \u003cb\u003eN\u003c/b\u003e \u003ci\u003esites\u003c/i\u003e in nature, labelled as \u003ci\u003eSite\u003c/i\u003e 1, \u003ci\u003eSite\u003c/i\u003e 2, ..., \u003ci\u003eSite\u003c/i\u003e \u003cb\u003eN\u003c/b\u003e. Researchers have identified an ecological network for you, which is given as a [1 x \u003cb\u003eN\u003c/b\u003e] row vector called \u003cb\u003eP\u003c/b\u003e. The network is read as follows: \"A chemical that enters \u003ci\u003eSite i\u003c/i\u003e always end up at \u003ci\u003eSite \u003cb\u003eP\u003c/b\u003e(i)\u003c/i\u003e\". Consider the following example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eIf a chemical enters Site:      1 2 3 4 5\r\n   it will end up at Site: P = [3 1 5 2 4]\r\n\u003c/pre\u003e\u003cp\u003eIf a harmful chemical enters the ecological network from \u003ci\u003eSite 2\u003c/i\u003e, it will be traced to \u003ci\u003eSite 1\u003c/i\u003e (which is \u003cb\u003eP\u003c/b\u003e(2)), then eventually at \u003ci\u003eSite 3\u003c/i\u003e, then at \u003ci\u003eSite 5\u003c/i\u003e, then at \u003ci\u003eSite 4\u003c/i\u003e, then back to \u003ci\u003eSite 2\u003c/i\u003e. Hence, the path of this chemical is [2 1 3 5 4].\u003c/p\u003e\u003cp\u003eWrite a function that takes a vector \u003cb\u003eP\u003c/b\u003e and a starting site \u003cb\u003eS\u003c/b\u003e. Output the path of the chemical after it enters \u003ci\u003eSite \u003cb\u003eS\u003c/b\u003e\u003c/i\u003e in the given ecological network. You are ensured that:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003eP\u003c/b\u003e is always a permutation of integers 1 to \u003cb\u003eN\u003c/b\u003e.\u003c/li\u003e\u003cli\u003e2 \u0026lt;= \u003cb\u003eN\u003c/b\u003e \u0026lt;= 100\u003c/li\u003e\u003cli\u003e1 \u0026lt;= \u003cb\u003eS\u003c/b\u003e \u0026lt;= \u003cb\u003eN\u003c/b\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSee sample test cases:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; trace_chemical([3 1 5 2 4],2)\r\n   ans = \r\n       2 1 3 5 4\r\n\u0026gt;\u0026gt; trace_chemical([3 1 5 2 4],1)\r\n   ans =\r\n       1 3 5 4 2\r\n\u0026gt;\u0026gt; trace_chemical([4 1 6 5 2 3],1)\r\n   ans =\r\n       1 4 5 2\r\n\u003c/pre\u003e","function_template":"function y = trace_chemical(P,S)\r\n  y = P;\r\nend","test_suite":"%%\r\nfiletext = fileread('trace_chemical.m')\r\nassert(isempty(strfind(filetext, 'rand')))\r\nassert(isempty(strfind(filetext, 'fileread')))\r\nassert(isempty(strfind(filetext, 'assert')))\r\nassert(isempty(strfind(filetext, 'echo')))\r\n%%\r\nP = [3 1 5 2 4];\r\nans = [2 1 3 5 4];\r\nassert(isequal(trace_chemical(P,2),ans))\r\n%%\r\nP = [3 1 5 2 4];\r\nans = [1 3 5 4 2];\r\nassert(isequal(trace_chemical(P,1),ans))\r\n%%\r\nP = [2 5 8 6 10 9 3 4 7 1 ];\r\nans = [8 4 6 9 7 3 ];\r\nassert(isequal(trace_chemical(P,8),ans))\r\n%%\r\nP = [36 15 70 23 1 60 35 13 19 41 48 20 49 44 68 29 9 61 51 38 ...\r\n     32 2 40 8 72 39 26 28 67 69 42 76 66 34 47 46 11 77 71 64 ...\r\n     4 37 80 18 74 52 7 33 58 50 27 3 45 55 65 43 21 54 31 6 ...\r\n     24 63 57 30 12 78 22 75 14 10 16 17 81 53 59 25 56 5 73 62 ...\r\n     79 ];\r\nans = [60 6 ];\r\nassert(isequal(trace_chemical(P,60),ans))\r\n%%\r\nP = [8 45 12 53 33 15 29 39 40 21 9 26 32 58 20 43 54 17 48 55 ...\r\n     5 49 37 57 16 46 36 10 34 6 38 50 11 27 22 42 19 4 13 47 ...\r\n     52 2 23 25 35 24 30 56 44 41 28 14 51 31 7 3 1 18 ];\r\nans = [35 22 49 44 25 16 43 23 37 19 48 56 3 12 26 46 24 57 1 8 ...\r\n     39 13 32 50 41 52 14 58 18 17 54 31 38 4 53 51 28 10 21 5 ...\r\n     33 11 9 40 47 30 6 15 20 55 7 29 34 27 36 42 2 45 ];\r\nassert(isequal(trace_chemical(P,35),ans))\r\n%%\r\nP = [9 28 7 42 18 16 30 17 24 20 41 29 13 15 44 8 27 23 12 19 ...\r\n     21 32 40 49 11 47 14 25 35 36 46 38 33 45 34 4 43 48 31 5 ...\r\n     3 10 26 39 37 1 22 6 2 ];\r\nans = [24 49 2 28 25 11 41 3 7 30 36 4 42 10 20 19 12 29 35 34 ...\r\n     45 37 43 26 47 22 32 38 48 6 16 8 17 27 14 15 44 39 31 46 ...\r\n     1 9 ];\r\nassert(isequal(trace_chemical(P,24),ans))\r\n%%\r\nP = [39 27 32 17 22 3 21 8 4 16 45 37 40 2 19 11 51 36 50 43 ...\r\n     13 44 12 30 48 28 42 35 10 14 5 38 15 9 20 18 6 26 31 24 ...\r\n     23 41 34 1 46 7 47 33 49 29 25 ];\r\nans = [11 45 46 7 21 13 40 24 30 14 2 27 42 41 23 12 37 6 3 32 ...\r\n     38 26 28 35 20 43 34 9 4 17 51 25 48 33 15 19 50 29 10 16 ];\r\nassert(isequal(trace_chemical(P,11),ans))\r\n%%\r\nP = [19 10 17 9 18 7 13 14 20 21 5 3 6 16 8 12 15 11 2 4 1];\r\nans = [4 9 20 ];\r\nassert(isequal(trace_chemical(P,4),ans))\r\n%%\r\nP = [12 1 5 66 26 29 64 68 2 33 38 41 55 8 18 49 27 47 22 50 ...\r\n     35 24 16 13 60 34 46 36 6 56 67 30 42 48 19 37 63 57 11 17 ...\r\n     40 59 15 23 45 32 61 44 53 31 28 10 62 9 21 7 52 14 39 51 ...\r\n     58 65 54 43 3 4 20 25 ];\r\nans = [26 34 48 44 23 16 49 53 62 65 3 5 ];\r\nassert(isequal(trace_chemical(P,26),ans))\r\n%%\r\nP = [65 8 29 66 49 72 61 38 18 33 58 62 67 40 20 27 46 1 5 6 ...\r\n     14 75 82 74 23 37 54 22 78 41 4 53 13 47 57 51 17 69 77 71 ...\r\n     64 35 25 44 21 70 19 76 36 10 81 42 60 79 28 31 9 48 3 56 ...\r\n     24 59 11 50 7 26 30 16 52 39 15 2 68 73 34 80 32 12 63 55 ...\r\n     45 43 ];\r\nans = [17 46 70 39 77 32 53 60 56 31 4 66 26 37 ];\r\nassert(isequal(trace_chemical(P,17),ans))\r\n%%\r\nP = [1 17 15 6 13 33 28 36 4 22 44 23 32 40 26 12 41 30 8 34 ...\r\n     37 14 21 5 9 10 29 3 35 38 11 43 31 16 19 27 24 45 39 7 ...\r\n     2 42 20 18 25 ];\r\nans = [14 40 7 28 3 15 26 10 22 ];\r\nassert(isequal(trace_chemical(P,14),ans))\r\n%%\r\nP = [1 17 21 15 6 24 13 5 4 18 2 9 3 29 10 28 12 23 11 25 ...\r\n     20 19 8 16 27 26 7 22 14 ];\r\nans = [10 18 23 8 5 6 24 16 28 22 19 11 2 17 12 9 4 15 ];\r\nassert(isequal(trace_chemical(P,10),ans))\r\n%%\r\nP = [6 2 3 4 1 7 5 ];\r\nans = [3 ];\r\nassert(isequal(trace_chemical(P,3),ans))\r\n%%\r\nP = [11 19 15 23 14 10 3 4 25 7 24 1 18 26 6 16 17 20 12 2 ...\r\n     13 22 9 21 8 5 ];\r\nans = [16 ];\r\nassert(isequal(trace_chemical(P,16),ans))\r\n%%\r\nP = [20 16 5 9 30 28 8 24 14 15 23 4 29 11 22 19 26 17 25 6 ...\r\n     27 18 3 2 1 13 31 12 10 21 7 ];\r\nans = [11 23 3 5 30 21 27 31 7 8 24 2 16 19 25 1 20 6 28 12 ...\r\n     4 9 14 ];\r\nassert(isequal(trace_chemical(P,11),ans))\r\n%%\r\nP = [1 18 16 8 15 21 27 22 23 17 26 19 3 4 9 11 7 6 29 2 ...\r\n     12 25 24 5 14 28 20 10 13 ];\r\nans = [22 25 14 4 8 ];\r\nassert(isequal(trace_chemical(P,22),ans))\r\n%%\r\nP = [38 48 42 87 57 89 92 12 20 62 59 51 26 29 45 55 10 71 44 69 ...\r\n     34 60 30 77 53 11 54 14 23 15 22 43 49 13 41 5 47 91 68 37 ...\r\n     9 3 76 31 85 33 40 1 63 70 18 8 17 35 90 36 24 83 94 21 ...\r\n     73 27 61 78 39 82 64 93 66 6 67 84 56 80 19 50 95 2 75 46 ...\r\n     74 16 81 72 4 25 86 32 28 52 65 58 88 7 79 ];\r\nans = [54 35 41 9 20 69 66 82 16 55 90 52 8 12 51 18 71 67 64 78 ...\r\n     2 48 1 38 91 65 39 68 93 88 32 43 76 50 70 6 89 28 14 29 ...\r\n     23 30 15 45 85 4 87 86 25 53 17 10 62 27 ];\r\nassert(isequal(trace_chemical(P,54),ans))\r\n%%\r\nP = [69 48 11 21 80 50 75 64 41 54 23 82 61 45 25 10 74 63 72 8 ...\r\n     15 81 42 60 59 65 35 37 70 33 76 24 36 49 56 18 38 6 44 39 ...\r\n     4 17 52 51 32 43 1 46 55 73 34 28 58 31 68 29 67 22 66 12 ...\r\n     53 5 16 77 19 7 13 26 57 79 3 47 71 40 14 30 2 20 62 9 ...\r\n     78 27 ];\r\nans = [27 35 56 29 70 79 62 5 80 9 41 4 21 15 25 59 66 7 75 14 ...\r\n     45 32 24 60 12 82 ];\r\nassert(isequal(trace_chemical(P,27),ans))\r\n%%\r\nP = [78 59 84 70 19 82 34 69 29 92 6 51 52 28 10 32 31 33 4 73 ...\r\n     24 89 99 68 64 47 46 95 94 21 53 44 62 26 93 91 58 55 98 79 ...\r\n     11 35 48 40 22 66 87 80 63 43 12 97 13 17 67 20 1 85 60 81 ...\r\n     25 50 88 49 96 90 76 83 36 15 75 23 41 86 39 9 8 54 7 61 ...\r\n     2 72 45 38 16 71 56 37 3 14 27 74 5 57 65 18 42 30 77 ];\r\nans = [85 16 32 44 40 79 7 34 26 47 87 56 20 73 41 11 6 82 72 23 ...\r\n     99 77 8 69 36 91 27 46 66 90 14 28 95 65 96 18 33 62 50 43 ...\r\n     48 80 61 25 64 49 63 88 37 58 ];\r\nassert(isequal(trace_chemical(P,85),ans))\r\n%%\r\nP = [86 17 25 63 38 72 9 64 56 10 7 26 43 28 36 40 24 71 41 22 ...\r\n     27 80 21 1 54 84 42 11 60 73 6 46 78 50 67 66 20 23 77 74 ...\r\n     57 44 85 75 16 13 47 14 29 48 19 58 2 39 81 83 59 33 49 61 ...\r\n     69 53 3 35 8 55 32 18 31 30 12 51 34 65 87 62 5 52 15 45 ...\r\n     4 68 82 76 70 37 79 ];\r\nans = [36 66 55 81 4 63 3 25 54 39 77 5 38 23 21 27 42 44 75 87 ...\r\n     79 15 ];\r\nassert(isequal(trace_chemical(P,36),ans))\r\n%%\r\nP = [25 7 4 6 16 30 24 28 9 3 31 13 10 23 2 26 29 8 5 20 ...\r\n     18 27 21 11 22 17 12 19 1 15 14 ];\r\nans = [21 18 8 28 19 5 16 26 17 29 1 25 22 27 12 13 10 3 4 6 ...\r\n     30 15 2 7 24 11 31 14 23 ];\r\nassert(isequal(trace_chemical(P,21),ans))\r\n%%\r\nP = [30 31 13 37 59 49 28 25 65 61 22 8 43 80 64 18 2 74 46 14 ...\r\n     85 12 62 5 55 67 48 42 78 83 47 15 79 89 34 68 54 90 3 44 ...\r\n     72 40 21 24 60 82 35 50 66 11 41 77 75 7 16 27 73 10 76 71 ...\r\n     33 56 39 53 38 19 36 84 69 81 23 87 9 51 70 86 88 1 26 57 ...\r\n     63 20 4 52 29 45 58 6 17 32 ];\r\nans = [78 1 30 83 4 37 54 7 28 42 40 44 24 5 59 76 86 45 60 71 ...\r\n     23 62 56 27 48 50 11 22 12 8 25 55 16 18 74 51 41 72 87 58 ...\r\n     10 61 33 79 26 67 36 68 84 52 77 88 6 49 66 19 46 82 20 14 ...\r\n     80 57 73 9 65 38 90 32 15 64 53 75 70 81 63 39 3 13 43 21 ...\r\n     85 29 ];\r\nassert(isequal(trace_chemical(P,78),ans))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2020-05-07T02:09:17.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-06T19:35:57.000Z","updated_at":"2025-12-07T16:54:53.000Z","published_at":"2020-05-06T19:53:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn ecological network consists of the cycles of nature, such as the water cycle, the carbon cycle, the oxygen cycle, etc. Due to human activities, harmful chemicals (or persistent pollutants) are now entering these cycles and may stay there forever. Your job is to track a specific unknown chemical inside an ecological network.\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, a network involves\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\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esites\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in nature, labelled as\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\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 1,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 2, ...,\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\u003eSite\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Researchers have identified an ecological network for you, which is given as a [1 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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e] row vector called\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\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The network is read as follows: \\\"A chemical that enters\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\u003eSite i\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e always end up at\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\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e(i)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e\\\". Consider the following 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[If a chemical enters Site:      1 2 3 4 5\\n   it will end up at Site: P = [3 1 5 2 4]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a harmful chemical enters the ecological network from\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\u003eSite 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, it will be traced 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSite 1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (which is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e(2)), then eventually at\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\u003eSite 3\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then at\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\u003eSite 5\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then at\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\u003eSite 4\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, then back 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSite 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Hence, the path of this chemical is [2 1 3 5 4].\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 takes a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a starting site\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\u003eS\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Output the path of the chemical after it enters\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\u003eSite\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eS\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the given ecological network. You are 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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eP\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is always a permutation of integers 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:b/\u003e\u003c/w:rPr\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2 \u0026lt;=\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026lt;= 100\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;=\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\u003eS\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026lt;=\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee sample test cases:\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 trace_chemical([3 1 5 2 4],2)\\n   ans = \\n       2 1 3 5 4\\n\u003e\u003e trace_chemical([3 1 5 2 4],1)\\n   ans =\\n       1 3 5 4 2\\n\u003e\u003e trace_chemical([4 1 6 5 2 3],1)\\n   ans =\\n       1 4 5 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1649,"title":"Magic - Faro Shuffle","description":"The Faro shuffle is the perfect interweaving of cards.  Quiz: How many Faro's returns a standard 52 deck to its start?  Fifty four cards require 52 shuffles while 64 cards requires only 6 shuffles.\r\n\r\nThis challenge is to return the vectors of shuffle results until the original sequence is re-created.\r\n\r\n*Input:* N  (number of cards-even; start sequence 1:N)\r\n\r\n*Output:* deck (Array of cards created by the Faro shuffles)\r\n\r\nExample: N=4, deck= [1 3 2 4;1 2 3 4]\r\n\r\nN=8, deck=[1 5 2 6 3 7 4 8;1 3 5 7 2 4 6 8;1 2 3 4 5 6 7 8 ] \r\n\r\n*Code Exclusions:* regexp, str2num  (enforced if necessary)\r\n","description_html":"\u003cp\u003eThe Faro shuffle is the perfect interweaving of cards.  Quiz: How many Faro's returns a standard 52 deck to its start?  Fifty four cards require 52 shuffles while 64 cards requires only 6 shuffles.\u003c/p\u003e\u003cp\u003eThis challenge is to return the vectors of shuffle results until the original sequence is re-created.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e N  (number of cards-even; start sequence 1:N)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e deck (Array of cards created by the Faro shuffles)\u003c/p\u003e\u003cp\u003eExample: N=4, deck= [1 3 2 4;1 2 3 4]\u003c/p\u003e\u003cp\u003eN=8, deck=[1 5 2 6 3 7 4 8;1 3 5 7 2 4 6 8;1 2 3 4 5 6 7 8 ]\u003c/p\u003e\u003cp\u003e\u003cb\u003eCode Exclusions:\u003c/b\u003e regexp, str2num  (enforced if necessary)\u003c/p\u003e","function_template":"function deck = Faro(n)\r\n  deck=1:n;\r\nend","test_suite":"%%\r\nn=52; % Quiz answer : Takes 8 Faro Shuffles\r\ndeck = Faro(n);\r\ndeck_exp=[1 27 2 28 3 29 4 30 5 31 6 32 7 33 8 34 9 35 10 36 11 37 12 38 13 39 14 40 15 41 16 42 17 43 18 44 19 45 20 46 21 47 22 48 23 49 24 50 25 51 26 52 \r\n1 14 27 40 2 15 28 41 3 16 29 42 4 17 30 43 5 18 31 44 6 19 32 45 7 20 33 46 8 21 34 47 9 22 35 48 10 23 36 49 11 24 37 50 12 25 38 51 13 26 39 52 \r\n1 33 14 46 27 8 40 21 2 34 15 47 28 9 41 22 3 35 16 48 29 10 42 23 4 36 17 49 30 11 43 24 5 37 18 50 31 12 44 25 6 38 19 51 32 13 45 26 7 39 20 52 \r\n1 17 33 49 14 30 46 11 27 43 8 24 40 5 21 37 2 18 34 50 15 31 47 12 28 44 9 25 41 6 22 38 3 19 35 51 16 32 48 13 29 45 10 26 42 7 23 39 4 20 36 52 \r\n1 9 17 25 33 41 49 6 14 22 30 38 46 3 11 19 27 35 43 51 8 16 24 32 40 48 5 13 21 29 37 45 2 10 18 26 34 42 50 7 15 23 31 39 47 4 12 20 28 36 44 52 \r\n1 5 9 13 17 21 25 29 33 37 41 45 49 2 6 10 14 18 22 26 30 34 38 42 46 50 3 7 11 15 19 23 27 31 35 39 43 47 51 4 8 12 16 20 24 28 32 36 40 44 48 52 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=16;\r\ndeck = Faro(n);\r\ndeck_exp=[1 9 2 10 3 11 4 12 5 13 6 14 7 15 8 16 \r\n1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16 \r\n1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 16 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=32;\r\ndeck = Faro(n);\r\ndeck_exp=[1 17 2 18 3 19 4 20 5 21 6 22 7 23 8 24 9 25 10 26 11 27 12 28 13 29 14 30 15 31 16 32 \r\n1 9 17 25 2 10 18 26 3 11 19 27 4 12 20 28 5 13 21 29 6 14 22 30 7 15 23 31 8 16 24 32 \r\n1 5 9 13 17 21 25 29 2 6 10 14 18 22 26 30 3 7 11 15 19 23 27 31 4 8 12 16 20 24 28 32 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=64;\r\ndeck = Faro(n);\r\ndeck_exp=[1 33 2 34 3 35 4 36 5 37 6 38 7 39 8 40 9 41 10 42 11 43 12 44 13 45 14 46 15 47 16 48 17 49 18 50 19 51 20 52 21 53 22 54 23 55 24 56 25 57 26 58 27 59 28 60 29 61 30 62 31 63 32 64 \r\n1 17 33 49 2 18 34 50 3 19 35 51 4 20 36 52 5 21 37 53 6 22 38 54 7 23 39 55 8 24 40 56 9 25 41 57 10 26 42 58 11 27 43 59 12 28 44 60 13 29 45 61 14 30 46 62 15 31 47 63 16 32 48 64 \r\n1 9 17 25 33 41 49 57 2 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 \r\n1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 ];\r\nassert(isequal(deck,deck_exp))\r\n%%\r\nn=54;\r\ndeck = Faro(n);\r\ndeck_exp=[1 28 2 29 3 30 4 31 5 32 6 33 7 34 8 35 9 36 10 37 11 38 12 39 13 40 14 41 15 42 16 43 17 44 18 45 19 46 20 47 21 48 22 49 23 50 24 51 25 52 26 53 27 54 \r\n1 41 28 15 2 42 29 16 3 43 30 17 4 44 31 18 5 45 32 19 6 46 33 20 7 47 34 21 8 48 35 22 9 49 36 23 10 50 37 24 11 51 38 25 12 52 39 26 13 53 40 27 14 54 \r\n1 21 41 8 28 48 15 35 2 22 42 9 29 49 16 36 3 23 43 10 30 50 17 37 4 24 44 11 31 51 18 38 5 25 45 12 32 52 19 39 6 26 46 13 33 53 20 40 7 27 47 14 34 54 \r\n1 11 21 31 41 51 8 18 28 38 48 5 15 25 35 45 2 12 22 32 42 52 9 19 29 39 49 6 16 26 36 46 3 13 23 33 43 53 10 20 30 40 50 7 17 27 37 47 4 14 24 34 44 54 \r\n1 6 11 16 21 26 31 36 41 46 51 3 8 13 18 23 28 33 38 43 48 53 5 10 15 20 25 30 35 40 45 50 2 7 12 17 22 27 32 37 42 47 52 4 9 14 19 24 29 34 39 44 49 54 \r\n1 30 6 35 11 40 16 45 21 50 26 2 31 7 36 12 41 17 46 22 51 27 3 32 8 37 13 42 18 47 23 52 28 4 33 9 38 14 43 19 48 24 53 29 5 34 10 39 15 44 20 49 25 54 \r\n1 42 30 18 6 47 35 23 11 52 40 28 16 4 45 33 21 9 50 38 26 14 2 43 31 19 7 48 36 24 12 53 41 29 17 5 46 34 22 10 51 39 27 15 3 44 32 20 8 49 37 25 13 54 \r\n1 48 42 36 30 24 18 12 6 53 47 41 35 29 23 17 11 5 52 46 40 34 28 22 16 10 4 51 45 39 33 27 21 15 9 3 50 44 38 32 26 20 14 8 2 49 43 37 31 25 19 13 7 54 \r\n1 51 48 45 42 39 36 33 30 27 24 21 18 15 12 9 6 3 53 50 47 44 41 38 35 32 29 26 23 20 17 14 11 8 5 2 52 49 46 43 40 37 34 31 28 25 22 19 16 13 10 7 4 54 \r\n1 26 51 23 48 20 45 17 42 14 39 11 36 8 33 5 30 2 27 52 24 49 21 46 18 43 15 40 12 37 9 34 6 31 3 28 53 25 50 22 47 19 44 16 41 13 38 10 35 7 32 4 29 54 \r\n1 40 26 12 51 37 23 9 48 34 20 6 45 31 17 3 42 28 14 53 39 25 11 50 36 22 8 47 33 19 5 44 30 16 2 41 27 13 52 38 24 10 49 35 21 7 46 32 18 4 43 29 15 54 \r\n1 47 40 33 26 19 12 5 51 44 37 30 23 16 9 2 48 41 34 27 20 13 6 52 45 38 31 24 17 10 3 49 42 35 28 21 14 7 53 46 39 32 25 18 11 4 50 43 36 29 22 15 8 54 \r\n1 24 47 17 40 10 33 3 26 49 19 42 12 35 5 28 51 21 44 14 37 7 30 53 23 46 16 39 9 32 2 25 48 18 41 11 34 4 27 50 20 43 13 36 6 29 52 22 45 15 38 8 31 54 \r\n1 39 24 9 47 32 17 2 40 25 10 48 33 18 3 41 26 11 49 34 19 4 42 27 12 50 35 20 5 43 28 13 51 36 21 6 44 29 14 52 37 22 7 45 30 15 53 38 23 8 46 31 16 54 \r\n1 20 39 5 24 43 9 28 47 13 32 51 17 36 2 21 40 6 25 44 10 29 48 14 33 52 18 37 3 22 41 7 26 45 11 30 49 15 34 53 19 38 4 23 42 8 27 46 12 31 50 16 35 54 \r\n1 37 20 3 39 22 5 41 24 7 43 26 9 45 28 11 47 30 13 49 32 15 51 34 17 53 36 19 2 38 21 4 40 23 6 42 25 8 44 27 10 46 29 12 48 31 14 50 33 16 52 35 18 54 \r\n1 19 37 2 20 38 3 21 39 4 22 40 5 23 41 6 24 42 7 25 43 8 26 44 9 27 45 10 28 46 11 29 47 12 30 48 13 31 49 14 32 50 15 33 51 16 34 52 17 35 53 18 36 54 \r\n1 10 19 28 37 46 2 11 20 29 38 47 3 12 21 30 39 48 4 13 22 31 40 49 5 14 23 32 41 50 6 15 24 33 42 51 7 16 25 34 43 52 8 17 26 35 44 53 9 18 27 36 45 54 \r\n1 32 10 41 19 50 28 6 37 15 46 24 2 33 11 42 20 51 29 7 38 16 47 25 3 34 12 43 21 52 30 8 39 17 48 26 4 35 13 44 22 53 31 9 40 18 49 27 5 36 14 45 23 54 \r\n1 43 32 21 10 52 41 30 19 8 50 39 28 17 6 48 37 26 15 4 46 35 24 13 2 44 33 22 11 53 42 31 20 9 51 40 29 18 7 49 38 27 16 5 47 36 25 14 3 45 34 23 12 54 \r\n1 22 43 11 32 53 21 42 10 31 52 20 41 9 30 51 19 40 8 29 50 18 39 7 28 49 17 38 6 27 48 16 37 5 26 47 15 36 4 25 46 14 35 3 24 45 13 34 2 23 44 12 33 54 \r\n1 38 22 6 43 27 11 48 32 16 53 37 21 5 42 26 10 47 31 15 52 36 20 4 41 25 9 46 30 14 51 35 19 3 40 24 8 45 29 13 50 34 18 2 39 23 7 44 28 12 49 33 17 54 \r\n1 46 38 30 22 14 6 51 43 35 27 19 11 3 48 40 32 24 16 8 53 45 37 29 21 13 5 50 42 34 26 18 10 2 47 39 31 23 15 7 52 44 36 28 20 12 4 49 41 33 25 17 9 54 \r\n1 50 46 42 38 34 30 26 22 18 14 10 6 2 51 47 43 39 35 31 27 23 19 15 11 7 3 52 48 44 40 36 32 28 24 20 16 12 8 4 53 49 45 41 37 33 29 25 21 17 13 9 5 54 \r\n1 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 54 \r\n1 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 54 \r\n1 27 53 26 52 25 51 24 50 23 49 22 48 21 47 20 46 19 45 18 44 17 43 16 42 15 41 14 40 13 39 12 38 11 37 10 36 9 35 8 34 7 33 6 32 5 31 4 30 3 29 2 28 54 \r\n1 14 27 40 53 13 26 39 52 12 25 38 51 11 24 37 50 10 23 36 49 9 22 35 48 8 21 34 47 7 20 33 46 6 19 32 45 5 18 31 44 4 17 30 43 3 16 29 42 2 15 28 41 54 \r\n1 34 14 47 27 7 40 20 53 33 13 46 26 6 39 19 52 32 12 45 25 5 38 18 51 31 11 44 24 4 37 17 50 30 10 43 23 3 36 16 49 29 9 42 22 2 35 15 48 28 8 41 21 54 \r\n1 44 34 24 14 4 47 37 27 17 7 50 40 30 20 10 53 43 33 23 13 3 46 36 26 16 6 49 39 29 19 9 52 42 32 22 12 2 45 35 25 15 5 48 38 28 18 8 51 41 31 21 11 54 \r\n1 49 44 39 34 29 24 19 14 9 4 52 47 42 37 32 27 22 17 12 7 2 50 45 40 35 30 25 20 15 10 5 53 48 43 38 33 28 23 18 13 8 3 51 46 41 36 31 26 21 16 11 6 54 \r\n1 25 49 20 44 15 39 10 34 5 29 53 24 48 19 43 14 38 9 33 4 28 52 23 47 18 42 13 37 8 32 3 27 51 22 46 17 41 12 36 7 31 2 26 50 21 45 16 40 11 35 6 30 54 \r\n1 13 25 37 49 8 20 32 44 3 15 27 39 51 10 22 34 46 5 17 29 41 53 12 24 36 48 7 19 31 43 2 14 26 38 50 9 21 33 45 4 16 28 40 52 11 23 35 47 6 18 30 42 54 \r\n1 7 13 19 25 31 37 43 49 2 8 14 20 26 32 38 44 50 3 9 15 21 27 33 39 45 51 4 10 16 22 28 34 40 46 52 5 11 17 23 29 35 41 47 53 6 12 18 24 30 36 42 48 54 \r\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 \r\n1 29 4 32 7 35 10 38 13 41 16 44 19 47 22 50 25 53 28 3 31 6 34 9 37 12 40 15 43 18 46 21 49 24 52 27 2 30 5 33 8 36 11 39 14 42 17 45 20 48 23 51 26 54 \r\n1 15 29 43 4 18 32 46 7 21 35 49 10 24 38 52 13 27 41 2 16 30 44 5 19 33 47 8 22 36 50 11 25 39 53 14 28 42 3 17 31 45 6 20 34 48 9 23 37 51 12 26 40 54 \r\n1 8 15 22 29 36 43 50 4 11 18 25 32 39 46 53 7 14 21 28 35 42 49 3 10 17 24 31 38 45 52 6 13 20 27 34 41 48 2 9 16 23 30 37 44 51 5 12 19 26 33 40 47 54 \r\n1 31 8 38 15 45 22 52 29 6 36 13 43 20 50 27 4 34 11 41 18 48 25 2 32 9 39 16 46 23 53 30 7 37 14 44 21 51 28 5 35 12 42 19 49 26 3 33 10 40 17 47 24 54 \r\n1 16 31 46 8 23 38 53 15 30 45 7 22 37 52 14 29 44 6 21 36 51 13 28 43 5 20 35 50 12 27 42 4 19 34 49 11 26 41 3 18 33 48 10 25 40 2 17 32 47 9 24 39 54 \r\n1 35 16 50 31 12 46 27 8 42 23 4 38 19 53 34 15 49 30 11 45 26 7 41 22 3 37 18 52 33 14 48 29 10 44 25 6 40 21 2 36 17 51 32 13 47 28 9 43 24 5 39 20 54 \r\n1 18 35 52 16 33 50 14 31 48 12 29 46 10 27 44 8 25 42 6 23 40 4 21 38 2 19 36 53 17 34 51 15 32 49 13 30 47 11 28 45 9 26 43 7 24 41 5 22 39 3 20 37 54 \r\n1 36 18 53 35 17 52 34 16 51 33 15 50 32 14 49 31 13 48 30 12 47 29 11 46 28 10 45 27 9 44 26 8 43 25 7 42 24 6 41 23 5 40 22 4 39 21 3 38 20 2 37 19 54 \r\n1 45 36 27 18 9 53 44 35 26 17 8 52 43 34 25 16 7 51 42 33 24 15 6 50 41 32 23 14 5 49 40 31 22 13 4 48 39 30 21 12 3 47 38 29 20 11 2 46 37 28 19 10 54 \r\n1 23 45 14 36 5 27 49 18 40 9 31 53 22 44 13 35 4 26 48 17 39 8 30 52 21 43 12 34 3 25 47 16 38 7 29 51 20 42 11 33 2 24 46 15 37 6 28 50 19 41 10 32 54 \r\n1 12 23 34 45 3 14 25 36 47 5 16 27 38 49 7 18 29 40 51 9 20 31 42 53 11 22 33 44 2 13 24 35 46 4 15 26 37 48 6 17 28 39 50 8 19 30 41 52 10 21 32 43 54 \r\n1 33 12 44 23 2 34 13 45 24 3 35 14 46 25 4 36 15 47 26 5 37 16 48 27 6 38 17 49 28 7 39 18 50 29 8 40 19 51 30 9 41 20 52 31 10 42 21 53 32 11 43 22 54 \r\n1 17 33 49 12 28 44 7 23 39 2 18 34 50 13 29 45 8 24 40 3 19 35 51 14 30 46 9 25 41 4 20 36 52 15 31 47 10 26 42 5 21 37 53 16 32 48 11 27 43 6 22 38 54 \r\n1 9 17 25 33 41 49 4 12 20 28 36 44 52 7 15 23 31 39 47 2 10 18 26 34 42 50 5 13 21 29 37 45 53 8 16 24 32 40 48 3 11 19 27 35 43 51 6 14 22 30 38 46 54 \r\n1 5 9 13 17 21 25 29 33 37 41 45 49 53 4 8 12 16 20 24 28 32 36 40 44 48 52 3 7 11 15 19 23 27 31 35 39 43 47 51 2 6 10 14 18 22 26 30 34 38 42 46 50 54 \r\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 \r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 ];\r\nassert(isequal(deck,deck_exp))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-14T22:13:26.000Z","updated_at":"2026-03-16T12:10:09.000Z","published_at":"2013-06-14T22:50:57.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 Faro shuffle is the perfect interweaving of cards. Quiz: How many Faro's returns a standard 52 deck to its start? Fifty four cards require 52 shuffles while 64 cards requires only 6 shuffles.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis challenge is to return the vectors of shuffle results until the original sequence is re-created.\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\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e N (number of cards-even; start sequence 1: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e deck (Array of cards created by the Faro shuffles)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: N=4, deck= [1 3 2 4;1 2 3 4]\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\u003eN=8, deck=[1 5 2 6 3 7 4 8;1 3 5 7 2 4 6 8;1 2 3 4 5 6 7 8 ]\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\u003eCode Exclusions:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e regexp, str2num (enforced if necessary)\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":45193,"title":"Fun with permutations","description":"There are factorial(N) permutations of the numbers from 1 to N. For each of these permutations, we can find the set of indexes j that will return the numbers to their original order, 1:N.  For example, if we generate a random permutation p with p = randperm(1:N) then the set of indices j that will return p to the original order\r\np(j) = 1:N may be found by [~,j] = sort(p).\r\n\r\nIt sometimes happens that this set of indices j and the corresponding permutation p are the same.  For example, if p = 1:N, then j = 1:N as well; and if p = N:-1:1, then\r\nj is also N:-1:1.  However, for N = 3, there are 6 permutations in all, and it happens that only 4 of them have this property.  \r\n\r\nYour task is to determine, given the value of N, the number of permutations p of the array 1:N for which the permutation p and the indexes j are the same.\r\n\r\ninput: N, the range of the integers,\r\noutput: The number of permutations of 1:N for which isequal(p,j)\r\n\r\nHINT: For N \u003c 12, you can probably solve this by checking each of the individual permutations, but for larger N this may prove to be too time-consuming.","description_html":"\u003cp\u003eThere are factorial(N) permutations of the numbers from 1 to N. For each of these permutations, we can find the set of indexes j that will return the numbers to their original order, 1:N.  For example, if we generate a random permutation p with p = randperm(1:N) then the set of indices j that will return p to the original order\r\np(j) = 1:N may be found by [~,j] = sort(p).\u003c/p\u003e\u003cp\u003eIt sometimes happens that this set of indices j and the corresponding permutation p are the same.  For example, if p = 1:N, then j = 1:N as well; and if p = N:-1:1, then\r\nj is also N:-1:1.  However, for N = 3, there are 6 permutations in all, and it happens that only 4 of them have this property.\u003c/p\u003e\u003cp\u003eYour task is to determine, given the value of N, the number of permutations p of the array 1:N for which the permutation p and the indexes j are the same.\u003c/p\u003e\u003cp\u003einput: N, the range of the integers,\r\noutput: The number of permutations of 1:N for which isequal(p,j)\u003c/p\u003e\u003cp\u003eHINT: For N \u0026lt; 12, you can probably solve this by checking each of the individual permutations, but for larger N this may prove to be too time-consuming.\u003c/p\u003e","function_template":"function y = funWithPerms(N)\r\n  y = N;\r\nend","test_suite":"%%\r\nN = 4;\r\ny_correct = 10;\r\nassert(funWithPerms(N) == y_correct);\r\n%%\r\nN = 6;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 38);\r\n%%\r\nN = 8;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 382);\r\n%%\r\nN = 10;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 2374);\r\n%%\r\nN = 12;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 35038);\r\n%%\r\nN = 14;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 298810);\r\n%%\r\nN = 16;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 5775842);\r\n%%\r\nN = 18;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 62332114);\r\n%%\r\nN = 20;\r\nassert(prod(unique(factor(funWithPerms(N)))) == 1484916506);\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":8580,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-11-03T23:25:57.000Z","updated_at":"2025-11-06T15:52:17.000Z","published_at":"2019-11-03T23:41:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are factorial(N) permutations of the numbers from 1 to N. For each of these permutations, we can find the set of indexes j that will return the numbers to their original order, 1:N. For example, if we generate a random permutation p with p = randperm(1:N) then the set of indices j that will return p to the original order p(j) = 1:N may be found by [~,j] = sort(p).\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\u003eIt sometimes happens that this set of indices j and the corresponding permutation p are the same. For example, if p = 1:N, then j = 1:N as well; and if p = N:-1:1, then j is also N:-1:1. However, for N = 3, there are 6 permutations in all, and it happens that only 4 of them have this property.\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\u003eYour task is to determine, given the value of N, the number of permutations p of the array 1:N for which the permutation p and the indexes j are the same.\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\u003einput: N, the range of the integers, output: The number of permutations of 1:N for which isequal(p,j)\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\u003eHINT: For N \u0026lt; 12, you can probably solve this by checking each of the individual permutations, but for larger N this may prove to be too time-consuming.\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:\"permutation\"","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:\"permutation\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"permutation\"","","\"","permutation","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f45df9b0a10\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f45df9b08d0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f45df9dfd38\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f45df9b0dd0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f45df9b0d30\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f45df9b0c90\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f45df9b0ab0\u003e":"tag:\"permutation\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f45df9b0ab0\u003e":"tag:\"permutation\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"permutation\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"permutation\"","","\"","permutation","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f45df9b0a10\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f45df9b08d0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f45df9dfd38\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f45df9b0dd0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f45df9b0d30\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f45df9b0c90\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f45df9b0ab0\u003e":"tag:\"permutation\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f45df9b0ab0\u003e":"tag:\"permutation\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":45498,"difficulty_rating":"easy-medium"},{"id":1649,"difficulty_rating":"easy-medium"},{"id":45193,"difficulty_rating":"medium"}]}}