I am trying to loop through an array, however I am encountering this problem. As I loop through this array:
{1,2,3,4}
I am encountering this problem: During the start, I will get combinations of 1 and 4, however near the middle I will get a combination of 4 and 1. How can I make it so only unique relationships will be accepted? There cant be anything like {1,4} and {4,1}.
I am using Java, there have been some answers to this however they use libraries only available in other languages.
I can't wrap my head around it to come up with even an attempt at a solution unfortunately.
Here is the expected output after looping through the array:
{1, 2}
{1, 3}
{1, 4}
{2, 3}
{2, 4}
{3, 4}
But here is what actually happens when looping through the array:
{1, 1}
{1, 2}
{1, 3}
{1, 4}
{2, 1}
{2, 2}
{2, 3}
{2, 4}
{3, 1}
{3, 2}
{3, 3}
{3, 4}
{4, 1}
{4, 2}
{4, 3}
{4, 4}
So the two requirements is that the pair has to be a unique relationship (can't have 1,2 and 2,1) and they can't be the same either. Not being the same could easily be done by comparing the two numbers and seeing if they are equal, but I am having trouble with the first requirement.