1

With 8 of 10 digits (ex: 0,1,2,3,4,5,6,7,8,9) we could have 1360800000 numbers; as you can see calculated here:

Partitions:
one digit appears 3 times, (example: 3749832414)
$\dbinom{8}{1}\dbinom{10}{2}\biggl(\dfrac{10!}{3!}\biggl)= 217728000$
two digits appear 2 times each. (example: 7364512193)
$\dbinom{8}{2}\dbinom{10}{2}\biggl(\dfrac{10!}{2!2!}\biggl)= 1143072000$
and sum of them is: 1360800000

The question is: how to get index of these numbers? For example, what is the index of 3749832414 or 7364512193?
There is a solution in this link, but it doesn't provide an index according to 10 digits, but provides an index according to digits that provided for the function. So it will return 0 for both 0123456777 and 0123456888 which does not answer the need for finding the index for each number if we consider 10 digits.
Edit
Leading zeros are allowed.
It doesn't matter how to index these numbers, just indexing them to be able to know what index represents what number and vise versa.
Edit
1360800000 is the count of numbers that have 8 of 10 digits and length of 10. In others words, all the 10 digit numbers that have two of their digits appeared two times each or one of their digits appeared 3 times like 3749832414 or 7364512193, in other words 1360800000 is count of all the permutations that have 2 global extra appearances of digits (0,1,2,3,4,5,6,7,8,9) in the length of 10 digits/symbols which causes the appearance of 8 digits out of 10 available digits.

Python code to calculate the count of these numbers:

c2 = binomial(8, 1) * binomial(10, 2) * (factorial(10) / factorial(3))
c11 = binomial(8, 2) * binomial(10, 2) * (factorial(10) / (factorial(2) * factorial(2)))
print(c2)
print(c11)
csum = c2 + c11
print("sum is: ", csum)

which prints :

217728000.000000
1143072000.00000
sum is: 1360800000.00000

Eftekhari
  • 141
  • $(1)$ Are leading zeros allowed ? $(2)$ Are the possible numbers sorted by their magnitude and then numbered according to this order ? – Peter Jan 02 '22 at 11:33
  • @Peter Edited question. – Eftekhari Jan 02 '22 at 11:52
  • Can you explain the 1360800000 ? – Gribouillis Jan 02 '22 at 11:55
  • @Gribouillis Edited the question. – Eftekhari Jan 02 '22 at 12:00
  • @Eftekhari Can you please use MATHJAX instead of picture etc. – Not a Salmon Fish Jan 02 '22 at 12:17
  • @Bulbasaur The question edited. – Eftekhari Jan 02 '22 at 13:12
  • 1
    Parts of the problem setup seem to have been left unstated: using a fixed set of eight digits, how many ten digit numbers can be formed? The goal could be better explained, as "index" can mean different things. You would like a method of enumerating the possible ten digit numbers, so that given $1\le k\le 1,360,800,000$ we can compute the corresponding entry in the list of solutions. – hardmath Jan 03 '22 at 15:47
  • @hardmath The index has to cover all the provided symbols which in this example is 10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) but I need to cover any number of symbols even 64 symbols like (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#) that in the case of 64, comes with a string with the length of 64 but with repetition of some of its symbols and for that it's not possible to use databases as it gets huge. Mathematical approaches are doable as that will be calculation of big numbers. – Eftekhari Jan 04 '22 at 04:44
  • Please ignore my comment on SO about there being a "simple" formula for this problem. I didn't understand that this is a specialized permutation problem with limits. So, some questions for you: 1. Can the 2 digits that repeat 2 times each be the same digit - i.e. 1, 1, 1, 1? 2. Is there just one set of digits that are constrained by the two conditions, or are there 2 sets? 3. Is 3334449821 valid (i.e. 2 digits that repeat 3 times)? 4. Is 4445566123 valid? If so, then it looks like you might be counting this twice, since it falls under both conditions. – Bob Bryan Jan 06 '22 at 10:41
  • @BobBryan Thanks for reviewing my question. 1. If we consider only 8 symbols of 10 symbols are allowed and have to be used, then 1111 is out of condition, meaning in 1111, 1 repeats 4 times and this lead to using 7 symbols instead of 8 in the length of 10 symbols. 2. I'm not sure If understood your second question correctly, but there is a requirement for any repetition in 8 symbols that could fill the length to 10 digits/symbols. The index that the example is looking for is from all the permutations that have 2 global extra appearances of digits in the length of 10 digits/symbols. 3. No 4. No – Eftekhari Jan 06 '22 at 11:24

1 Answers1

1

$\color{red}{\text{Warning!}}$ I am writing this answer to show the mathematical approach , but this is very cumbersome , so i recommend you to use computer program instead of combinatorical approach.

Saying that the first digit can be zero , make our work easier.I think saying "strings" instead of "digits" can be more appropriate in that sense.Anyway , lets turn our attention.I think that the best way to count these numbers is to use exponential generating functions.Otherwise ,it would be so cumbersome to deal with .

As you indicated ,a number can repeat at most $3$ times because there is $8$ distinct number in this string of lenght $10$.Then , the E.G.F of each number can be $$\bigg(x + \frac{x^2}{2!}+\frac{x^3}{3!}\bigg)$$

Now , for $3749832414$, we must firstly count how many string there are such that starting with $0$ , $1$ ,$2$.

  • For the strings start with $0$ :

If it starts with zero , then the E.G.F form of zero is $$\bigg(x + \frac{x^2}{2!} \bigg)$$ Now choose the rest $7$ digits by $\binom{9}{7}$.

So ,the number of strings of lenght $10$ starting with zero and containg $8$ distinct numbers is : $$[x^{10}]\bigg(x + \frac{x^2}{2!}+\frac{x^3}{3!}\bigg)^7\bigg(x + \frac{x^2}{2!}\bigg)$$

This calculation is also valid for those strings that start with $1$ or $2$ .So when we come up to the strings starst with $3$ there are $3 \times [x^{10}] \times \binom{9}{7}$ strings.

  • For starting with $30$ :

We need to select $6$ numbers among the rest $8$ by $\binom{8}{6}$ , and find $$[x^{10}]\bigg(x + \frac{x^2}{2!}+\frac{x^3}{3!}\bigg)^6\bigg(x + \frac{x^2}{2!}\bigg)^2$$

This is valid for starting with $31,32,34,35,36$ ,so $$6 \times \binom{8}{6}[x^{10}]$$

However ,for those starting with $33$ , the E.G.F is $$[x^{10}]\bigg(x + \frac{x^2}{2!}+\frac{x^3}{3!}\bigg)^7\bigg(x \bigg)$$

Moreover, we must select $7$ numbers instead of $6$ ,so $$\binom{9}{7}[x^{10}]\bigg(x + \frac{x^2}{2!}+\frac{x^3}{3!}\bigg)^7\bigg(x \bigg)$$

Now , you must the number of strings starting with $370,371,372,373$ using the same logic.This process will be applied for each next digits.I hope you understand the logic.

However, this is very cumber some as i said , so i would recommend you to use computer program.

  • Thank you. Would you please convert it into understandable python or java or c# code to see the logic more clearly? With python or java or C# please do not consider my example and make it a function that takes 2 parameters like number_to_index(number_that_has_repetition, strings_to_choose_from). For example number_to_index(3749832414, {0,1,2,3,4,5,6,7,8,9}): – Eftekhari Jan 02 '22 at 16:11
  • @Eftekhari i am not good at coding , i am sorry. – Not a Salmon Fish Jan 02 '22 at 16:18
  • Thank you again. – Eftekhari Jan 02 '22 at 16:20
  • @Eftekhari you are welcome! – Not a Salmon Fish Jan 02 '22 at 16:21
  • "- For the strings start with $0$ :

    If it starts with zero , then the E.G.F form of zero is" $$\bigg(x + \frac{x^2}{2!} \bigg)$$ why is that? If you could provide a source to learn about this method.

    – Eftekhari Jan 04 '22 at 07:28
  • "x" is the index of each symbol? Having 10 symbols {0,1,2,3,4,5,6,7,8,9} in this example indexes are equal to the symbols but in {a, b, c, d, e, f, g, h, i, j} what to put in x? Index of these symbols? So, have to sum the up at the end? – Eftekhari Jan 04 '22 at 07:40
  • what is x^10 for? – Eftekhari Jan 05 '22 at 16:30