Calculating number of permutations