Unique number from 6 different numbers <= 49 and its inverse

64 Views Asked by At

I know how to compute a unique number for 6 different numbers <= 49. The algorithm is simple:

def number_for_selected_numbers(selected_numbers):
    selected_numbers = sorted(selected_numbers)
    result = 0
    for i, number in enumerate(selected_numbers):
        result += binomial_coefficient(49 - number, 6 - i)
    return result

My question is how to compute 6 different number for given number from 1...~14M (where ~14M is a number for all possible combination of 6 different numbers).

1

There are 1 best solutions below

0
On

For the first number, it will be the minimum value of $a$ such that $\dbinom{49-a}{6}<\text{number}$.

The second number, it will be the minimum value of $b$ such that $\dbinom{49-b}{5}<\text{number}-\dbinom{49-a}{6}$.

The third number, it will be the minimum value of $c$ such that $\dbinom{49-c}{4}<\text{number}-\dbinom{49-a}{6}-\dbinom{49-b}{5}$.

Etc.

Note:

$1\le a \le 44$

$a+1\le b \le 45$

$b+1 \le c \le 46$

$c+1\le d \le 47$

$d+1\le e\le 48$

$e+1\le f \le 49$

So, that should make your loops pretty efficient. You can just loop from 1 to 49 once and after you find all six numbers, break.