A nice explanation of the algorithm; thanks.
However, this part isn't quite right.
in reply to Re: Steinhaus - Johnson - Trotter Algorithm for Permutations (explain)
in thread Steinhaus - Johnson - Trotter Algorithm for Permutations
In the language of group theory,
(0..$#e) is the
identity, while @o, @p are inverses of each other. Thus @p[@o]=@o[@p]=(0..$#e).
> # @p is the position of each element in @o,
> # that is, @o = (0..$#e)[@p]
> my @p= (0..$#e);
> # Note that it is also true that @p = (0..$#e)[@o].
# an arbitrary permutation
@o = @permutation = (1,2,0);
# position of 0 is in $o, so $p=2.
# This leads to
@p = @positions = (2,0,1);
# And then
print " o[p] = (@o[@p]) = p[o] = (@p[@o]) \n";
o[p] = (0 1 2) = p[o] = (0 1 2)