I have two arrays of 2D points:
array1 = int[x][2]
array2 = int[y][2]
From this two arrays I want to generate combinations of 4 points. The results should go in a list:
List<int[4][2]>
But I need to specify how many points I’m taking from array1 for each combination (and take the remaining from array2). The order of the points does not matter. And there should be no repetition.
For example:
array1={ {0,0} , {0,1} , {1,0} }
array2= { {1,1} , {2,1} , {2,2} , ... , {9,9} }
(Take 1 point from array1 and 3 points from array2)
res= { {0,0} , {1,1} , {2,1} , {2,2} }
{ {0,0} , {1,1} , {2,1} , {3,2} }
...
{ {0,0} , {1,1} , {2,1} , {9,9} }
...
{ {0,1} , {1,1} , {2,1} , {2,2} }
...
Never :
res = { {0,0} , {1,1} , {1,1} , {1,1} }
...
Neither :
res= { {0,0} , {1,1} , {2,1} , {2,2} }
{ {0,0} , {1,1} , {2,2} , {2,1} }
...
(Take 2 points from array1 and 2 points from array2)
…
(Take 3 points from array1 and 1 point from array2)
…
I hope someone can help me on this because I’ve spent many hours reading/testing many many answers and couldn’t find a solution.
PS/Edit: If you could provide code in C# that would be great.
This question has been simplified by your stipulation that you can only retrieve points in the order in which they are stored in the original array.EDIT: This question has been simplified by your stipulation that the result should contain combinations, not permutations. So to simplify things we can retrieve points in the order in which they are stored in the original array, which avoids permuting them.
You offered to translate from any other language so I’ll use JavaScript. Note that JavaScript arrays include their length, so you’ll need to pass the length separately (or alternatively pass the end of the array).