Permutations by swapping: Difference between revisions
m
→{{header|J}}
(J draft) |
m (→{{header|J}}) |
||
Line 19:
Meanwhile, here's an inductive approach, using negative integers to look left and positive integers to look right:
<lang J>
lookingat=: 0 >. <:@# <. i.@# + *
next=: | >./@:* | > | {~ lookingat
Here,
To convert from the Steinhaus–Johnson–Trotter representation of a permutation to J's representation, use <:@|, or to find J's permutation index of a Steinhaus–Johnson–Trotter representation of a permutation, use A.<:@|
Line 30:
Example use:
<lang J>
_1 _2 _3
_1 _3 _2
Line 37:
_2 3 _1
_2 _1 3
<:@|
0 1 2
0 2 1
Line 44:
1 2 0
1 0 2
A. <:@|
0 1 4 5 3 2</lang>
|