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.

Sokko
  • 11
  • 1
    https://learn.microsoft.com/dotnet/api/system.array.indexof –  Jun 12 '21 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. – Franz Gleichmann Jun 12 '21 at 15:27
  • @OlivierRogier i need something faster than this – Sokko Jun 12 '21 at 15:29
  • Why `16` is not filled as `0,0,1,0` instead of `0,0,1,1`? – user1672994 Jun 12 '21 at 15:29
  • You need a hash code (dictionary). See : https://stackoverflow.com/questions/3404715/c-sharp-hashcode-for-array-of-ints – jdweng Jun 12 '21 at 15:40
  • @Sokko Using an array, you can't get faster. Use HashSet or anything else more relevant: https://stackoverflow.com/questions/6242311/get-index-of-array-element-faster-than-on –  Jun 12 '21 at 15:41
  • @user1672994 Need values to be in ascending order like this, I generated them based on combinations with repetition. – Sokko Jun 12 '21 at 15:41

0 Answers0