perms(3) print perms(4) end sub perms(n) dim p((n+1)*4) for i = 1 to n p(i) = -i next i s = 1 repeat print "Perm: [ "; for i = 1 to n print abs(p(i)), " "; next i print "] Sign: ", s k = 0 for i = 2 to n if p(i) < 0 and (abs(p(i)) > abs(p(i-1))) and (abs(p(i)) > abs(p(k))) k = i next i for i = 1 to n-1 if p(i) > 0 and (abs(p(i)) > abs(p(i+1))) and (abs(p(i)) > abs(p(k))) k = i next i if k then for i = 1 to n //reverse elements > k if abs(p(i)) > abs(p(k)) p(i) = -p(i) next i i = k + sig(p(k)) temp = p(k) p(k) = p(i) p(i) = temp s = -s endif until k = 0 end sub