Let's say I have 3 identical arrays, each looks like this: [1,2,3,4]
.
By choosing a value from each array, I want to exhaust all combinations, so in this example, the desired result would be:
[1,2,3], [1,2,4], [1,3,4],[2,3,4]
Order doesnt matter. I'm currently iterating over every possibility, and that's waaaay too slow.
I thought about first doing a check to make sure the iterator is greater than the one to the left of it, but in the case of 1,4,...
that would fail because the 3rd array doesn't have anything bigger than 4. So additionally I'd need to do a check to make sure the max of each column is no greater than column length - (# of repeating columns - column position
. For example column 2 could not exceed 3. But I think I'm going down the rabbit hole.
Any clever ways to get the desired result in the fewest iterations possible? Modifying the arrays is fair game, too.