I have array (int[3876][4]) as seen below and I want to find quickest way to calculate index of it based on the given numbers. For example, given numbers [0,0,1,2] should return index = 17, numbers [3,7,9,12] = 2366, [14,14,14,15] = 3872 etc.
For n = 16, k = 4
I have a total (n+k-1)!/(k!(n-1)!) = 3876 combinations
Index
0 | 0,0,0,0
1 | 0,0,0,1
2 | 0,0,0,2
3 | 0,0,0,3
4 | 0,0,0,4
5 | 0,0,0,5
6 | 0,0,0,6
7 | 0,0,0,7
8 | 0,0,0,8
9 | 0,0,0,9
10 | 0,0,0,10
11 | 0,0,0,11
12 | 0,0,0,12
13 | 0,0,0,13
14 | 0,0,0,14
15 | 0,0,0,15
16 | 0,0,1,1
17 | 0,0,1,2
18 | 0,0,1,3
... | ...
3870 | 13,15,15,15
3871 | 14,14,14,14
3872 | 14,14,14,15
3873 | 14,14,15,15
3874 | 14,15,15,15
3875 | 15,15,15,15
Here you can see whole array pattern.