Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How many distinct digit permutations exist for a specific N-digit number?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It would be

N! / (#0! * #1! * #2! * #3! * #4! * .. * #9!)

with #d number of d.

N! is total number of permutation of distinct element.

consider then 1a, 1b as disting 1, we have to divide N! by permutation number of 1 (and also for other numbers).

So for 1112235 it would be

7! / (3! * 2! * 1! * 1!) (ignoring 0! which is 1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading