I'm not sure how to title the question I have so I can't be certain this hasn't been answered before. That said, following is a description of my programming question.
I have a class R containing 2 integer elements, say X and Y. I then have two 24 element arrays named A and B where each element contains an instance of class R. I would like to iterate through the arrays to determine how to use R.Y to populate a third array C as follows:
If R.Y at index i of A is larger than R.Y at index i of B then put R from A into index i of C.
If R.Y at index i of B is larger than R.Y at index i of A then put R from B into index i of C.
If R.Y at index i of A is equal to R.Y at index i of B then put either R into index i of C.
It's the third of these conditions that has me perplexed. For example, if indexes 7, 15, and 19 of arrays A and B have R.Y equal to each other, then I want to try each element of both A and B at those indexes in C to determine which one is required based on a CRC check of C. So I could put the following R values into the same index values of C:
A, A, A
A, A, B
A, B, A
A, B, B
B, A, A
B, A, B
B, B, A
B, B, B
These 8 combinations come from 2^3 (2 arrays to the power of the number of times R.Y are the same), so if I have 4 indexes in A and B where R.Y are equal, then there would be 16 combinations, 5 indexes = 32 combinations, 6 = 64, etc.
The issue is I'll never know how many times R.Y will be identical in A and B for all the indexes; it could be 0 to 24. So to make a long description short, I need an algorithm to populate C with all the possible R classes from A and B where R.Y are equal in both arrays, iterate through all the possible combinations of C and stop when that first instance of C passes the CRC check.
Sound simple? I hope so. Let me know if you need any further clarification or point me to a thread that has something similar to this already answered. TIA