0

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.

7
  • 1
    learn.microsoft.com/dotnet/api/system.array.indexof Commented Jun 12, 2021 at 15:23
  • if that's the actual data, i recommend simply converting hexadecimal to decimal instead. that way, you don't need to fill the array and aren't limited to 4 hex digits. Commented Jun 12, 2021 at 15:27
  • @OlivierRogier i need something faster than this Commented Jun 12, 2021 at 15:29
  • Why 16 is not filled as 0,0,1,0 instead of 0,0,1,1? Commented Jun 12, 2021 at 15:29
  • You need a hash code (dictionary). See : stackoverflow.com/questions/3404715/… Commented Jun 12, 2021 at 15:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.