The problem is simple. We have an N-digit digit number (N <= 18) and we need to know all the possible distinct combinations of this number. For example the answer for the number 214 (N = 3) is 6 (You can create 214, 241, 124, 142, 412, 421). I'm looking for an algorithm that calculates this.
I noticed that for an N-digit number the maximum amount of different numbers is equal to N!. However I have no clue on how this thing works when the digit are not distinct. I tried several methods for example trying to write a formula to make it or code but nothing worked.
It would be
with
#dnumber ofd.N!is total number of permutation of distinct element.consider then
1a,1bas disting1, we have to divideN!by permutation number of1(and also for other numbers).So for
1112235it would be7! / (3! * 2! * 1! * 1!)(ignoring0!which is1)