2

I have a 7 dimensional jagged array that essentially is just a collection of decimal numbers. I need to go through the array and add up all the decimals that have certain values in certain columns. For example;

(A)(B)(..)(..)(..)(..)(..)

Where .. is the entire size of the dimention. For the above case I can simply use a bunch of nested for loops because I know that A and B are at the start of the array. But how can I deal with this if the dimention in which A and B are located is randomised. Eg.

(..)(A)(..)(..)(B)(..)(..)
Or
(..)(..)(..)(..)(..)(A)(B)
Or
(..)(..)(A)(..)(..)(..)(B)
Etc.

I thought about have a select case for the locations of A and B but this leads to hundreds (if not thousands) of lines of repeated code, and it feels like bad practice.

Any suggestions?

Edit #1 This is difficult to explain so I'm going to use a much more simple example. Instead of 7 dimentions let's say it's 2 dimentions (each with a length of 4). And instead of A and B let's say it's just A. I wish to add the following elements:

(A)(0)
(A)(1)
(A)(2)
(A)(3)
(0)(A)
(1)(A)
(2)(A)
(3)(A)

As you can see this is every element where A is in either of the dimentions (A is a real number, in this case either 0, 1, 2, or 3). Now in my case there's the need for both A and B to be in one of the dimentions and the requirement that A is always before B. But since there's 7 dimentions there's so many possible locations of A and B that writing code to each scenario is not ideal (also I'd like to extend it to C, D, etc.)

user6916458
  • 400
  • 2
  • 7
  • 19
  • `Recursion` ??? – Ryan Wilson Jan 21 '19 at 18:11
  • 7 dimensional? Or an array with 7 elements? – the_lotus Jan 21 '19 at 18:13
  • I'm sure recursion is the answer. I just don't know how to sort it! – user6916458 Jan 21 '19 at 18:13
  • 7 dimensional. In total (across all dimentions) there's roughly 100 million elements. – user6916458 Jan 21 '19 at 18:14
  • Is it [something like this](https://stackoverflow.com/a/51922659/7444103)? There, is calculated the average of the *vertical* values of a jagged array. The comparison here is between two arrays of values extended along the *vertical* dimension, if I have understood your requirements. – Jimi Jan 21 '19 at 19:40
  • I don't get what you're trying to do. Sum the content of your collections? And, if so, do you need to keep these summations handy, or is it just an output? – laancelot Jan 22 '19 at 03:43
  • I'll edit the question to add more detail. – user6916458 Jan 22 '19 at 03:45
  • Better, but still kinda fuzzy. Could you describe in therms of "here's the input or starting situation" "here I have to make some treatment" "here's the desired result"? – laancelot Jan 22 '19 at 13:27
  • Do you need to "find" A and B, to "insert" A and B, to "count" A and B, to... i'm not sure. – laancelot Jan 22 '19 at 13:29

0 Answers0