Permutations/Rank of a permutation: Difference between revisions
Permutations/Rank of a permutation (view source)
Revision as of 09:54, 27 October 2012
, 11 years ago→{{header|J}}: complete first 4 tasks
(→{{header|J}}: Start J solution) |
(→{{header|J}}: complete first 4 tasks) |
||
Line 51:
The J primitive <code>A.</code> provides an effective solution to this task.
<lang j> A.
4
A. 2 3 1 0▼
2 0 1
(i.@! A.
0 1 2
0 2 1
▲ 17 A. 0 1 2 3 NB. return permutation of rank 17
1 2 0
2
2 1 0
A. (i.@! A. i.) 3 NB. ranks of each permuation
]ranks=: 4 ? !12 NB. 4 random numbers sampled from integers 0 to 12!
315645285 249293994 432230943 23060830
ranks A. i.12 NB. 4 random samples of 12 items
7 10 11 8 4 0 2 3 9 5 6 1
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>
=={{header|Python}}==
|