in-place calculation of permutations