Superpermutation minimisation: Difference between revisions

m
→‎version 1: aligned statement, changed whitespace.
m (→‎version 1: aligned statement, changed whitespace.)
Line 1,752:
 
do n=0 to cycles
#= 0; $.= /*populate the first permutation. */
do pop=1 for n; @.pop= d2x(pop); $.0= $.0 || @.pop
end /*pop*/
 
do while aPerm(n, 0)
if n\==0 then #= #+1; $.#=
do j=1 for n; $.#= $.# || @.j
end /*j*/
end /*while*/
z= $.0
nm= n-1
do p=1 for #; if $.j=='' then iterate; if pos($.p, z)\==0 then iterate
parse var $.p h 2 R 1 L = if pos(n$.p, z)\==0 then iterate
ifparse left(z,var nm)==R then$.p do; z= h ||2 z;R 1 iterate;L end=(n)
if right left(z, 1nm)==hR then do; z= zh || Rz; iterate; end
if right(z, 1)==h then do; z= z || R; iterate; end
z= z || $.p
end /*p*/ /* [↑] more IFs could be added for opt*/
 
L= commas( length(z) )
say 'length of superpermutation('n") =" right(L, max(length(L), cycles+2) )
end /*cycle*/
exit 0 /*stick a fork in it, we're all done. */