Given a constant list const
, e.g.
const = {-(15/2), -(13/2), -(17/2), -(15/2), -(13/2), -(11/2)}
of length n
, I want to find all permutations perm
of Range[n]
such that
res = perm + const
is duplicate free. I can do
Pick[#, UnsameQ @@@ (# + ConstantArray[const, n!])] & [Permutations[Range[n]]]
which is pretty fast, especially when I can make const
a packed array, but I need to do this inside a loop over lots of different const
vectors, and I seem to typically discard close to 80% of the permutations. So I am looking for a better alternative, hopefully one where I don't need to first generate all permutations and then pick valid ones.
I had a similar problem earlier, but wasn't concerned with duplicates then, so I don't know how or if the solution can be modified to my new problem.