Permutations by swapping: Difference between revisions

Content added Content deleted
Line 24:
bfsjtn=: (((] <@, ] + *@{~) | i. next) C. ] * _1 ^ next < |)^:(*@next)</lang>
 
Here, bfsjt0 N gives the initial permutation of order N, and bfsjtn^:M bfsjt0 MN gives the Mth Steinhaus–Johnson–Trotter permutation of order N. (bf stands for "brute force".)
 
To convert from the Steinhaus–Johnson–Trotter representation of a permutation to J's representation, use <:@|, or to find J's anagram index of a Steinhaus–Johnson–Trotter representation of a permutation, use A.<:@|