A subset of permutations is called derangements (all elements out of
position).
AFAICS these are the only candidates for at least one swop in the
rosetta code task
topswops: http://rosettacode.org/wiki/Topswops
So far I formulated two verbs for obtaining this subset.
A selector
derangements=: ((%~}.i.@])!) (](*./@:~:"1 #]) A.) 1+i.
A generator
derangements2=: [: (;@:( <@(],"1 0 (-.[,1+#))"1)^: (#@]`]) ,.@}.)1+i.
derangements 4
2 1 4 3
2 3 4 1
2 4 1 3
3 1 4 2
3 4 1 2
3 4 2 1
4 1 2 3
4 3 1 2
4 3 2 1
By using derangements the execution time of topswops can be reduced by a
factor of approx. 1x1.
FYI
--
Met vriendelijke groet,
@@i = Arie Groeneveld
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm