I have three arrays:
[0, 0, 2.5, 2.5, ]
[0, 0.5, 0, 0,]
[0, 2.0, 0, 0, ]
I am looking for an algorithm to loop through them all and add them to the first array ONLY if we can achieve the same value in the index of that array (2.5 in this case), delete them if they are added and leave out all the other arrays that do not fit (e.g. [0,0,0,0.001]
), I can't even begin to wrap my head around this one, the tricky part to me is identifying whether a combination of two (or more) other arrays can fill the first one.
For example if we add [0, 0.5, 0, 0,] to [0, 0, 2.5, 2.5, ] we get [0, 0.5, 2.5, 2.5, ] and the same for the last one, so the method should be able to detect that and add them both to the first one and delete it, leaving any 'impossible' arrays.