Permutations/Rank of a permutation: Difference between revisions

→‎{{header|J}}: stretch task
m (→‎{{header|J}}: simplify)
(→‎{{header|J}}: stretch task)
Line 49:
 
=={{header|J}}==
The J primitive <code>A.</code> provides an effective solution to this task. Generating 4 random permutations of 144 items takes about 6 milliseconds so solving the Stack Overflow question should be readily acheivable.
 
<lang j> A. 2 0 1 NB. return rank of permutation
Line 70:
6 2 8 11 10 0 5 9 7 1 3 4
10 9 1 2 0 3 8 6 7 5 11 4
0 7 4 6 11 5 10 3 9 8 1 2</lang>
(4 ?@$ !144x) A. i.144 NB. 4 random samples of 144 items
117 36 129 85 128 95 27 14 15 119 45 60 21 98 135 106 18 64 132 97 79 84 35 139 101 75 59 13 141 99 86 40 10 140 23 92 125 6 68 41 69 20 56 12 127 65 142 116 71 54 1 5 121 8 78 73 48 30 80 131 111 57 66 100 138 77 37 124 136...
111 65 136 58 92 46 4 83 20 54 21 10 72 110 56 28 13 18 73 133 105 117 63 126 114 43 5 80 45 88 86 108 11 29 0 129 71 141 59 53 113 137 2 102 95 15 35 74 107 61 134 36 32 19 106 100 55 69 76 142 64 49 9 30 47 123 12 97 42...
64 76 139 122 37 127 57 143 32 108 46 17 126 9 51 59 1 74 23 89 42 124 132 19 93 137 70 86 14 112 83 91 63 39 73 18 90 120 53 103 140 87 43 55 131 40 142 102 107 111 80 65 61 34 66 75 88 92 13 138 50 117 97 20 44 7 56 94 41...
139 87 98 118 125 65 35 112 10 43 85 66 58 131 36 30 50 11 136 130 71 100 79 142 40 69 101 84 143 33 95 26 18 94 13 68 8 0 47 70 129 48 107 64 93 16 83 39 29 81 6 105 78 92 104 60 15 55 4 14 7 91 86 12 31 46 20 133 53...</lang>
 
=={{header|Python}}==
892

edits