I've been working, giving up and then reworking on this problem for a couple days. I've looked at a lot of different ways to go about however I either can't implement it correctly or it doesn't suit what I need it to do.
Basically: I have two arrays, prefix and suffix
prefix = { 0, 0, 3, 8, 8, 15}
suffix = { 0, 3, 2, 7, 7, 9, 12, 15 }
I need to:
- Have a minimum of 3 used combined (2+1 or 1+2) and a max of 6 used (3+3).
- Not use an affix more than once (except when it's repeated (ie there's two 8's in prefix))
The end goal is to see what combinations can equal X.
eg
X = 42
3 + 8 + 8 + 2 + 9 + 12 = 42
0 + 8 + 8 + 7 + 7 + 12 = 42
| Prefix | | Suffix |
15 + 12 + 15 = 42
0 + 15 + 0 + 12 + 15 = 42
I've tried looking into Permutations, IEnumerables, Concat's etc. but cannot find something that'll do this successfully.
These are the 'full' arrays I'm needing to work with.
public int[] Prefix = {0, 6, 6, 8, 8, 8, 8, 8, 8, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 15, 15, 18, 18, 18, 18, 18, 18, 23 };
public int[] Suffix = {0, 3, 3, 9, 11, 11, 11, 17, 18, 18, 20, 25, 25, 27, 30, 30};
Any help is appreciated, if I'm unclear about anything I'll clarify as best as possible, Thanks!
Edit: I was also suggested to run it to equate all possible outcomes and store it in a hash table to be used when the correct values are used? Not sure which would work best.
Prefixhas six entries of8, seven entries for12, andSuffixhas three entries of11. If you you're solving for a sum of31, I think that will yield 126 duplicate results based on those entries alone.