Any combination of array elements?

Hello friends,
how would I detect if an array of five integers (each item can be any integer between 0-8) contains precise five numbers, but in ANY order? So for example, if the array is 1-0-0-0-0, and I compare it to 0-0-1-0-0, I still want to get TRUE in the end, because both contain one 1 and four 0’s. Or if the array is 5-4-1-0-2, I want it to be TRUE when I compare it to 2-0-4-5-1. Because there are the same numbers, but just in a different order. You get the point. I just don’t know how to do this efficiently in a blueprint. Can anyone help me with this please? Thanks in advance!

This is the basic premise. If you want to compare things like length or such that’s up to you.

Edit: One thing I forgot in the pick is for the bottom “OR” option in integer comparison, plug in the Array Element Node (so that it compares it with the accepted null).

Cheers.

Thank you for the answer, I’m gonna try it out, but first - what is Accepted Null?

Accepted null is just an option for you to be able to add exceptions (so that whether or not such digit is present is irrelevant). You could even make Accepted Null an array depending on your needs. If you don’t need it (in this case, your only accepted null is the 0, you can omit it. It’s just a nice thing to include (for general purposes).

I omitted the accepted null, because 0 always equals 0 so the OR is always true, therefore everything was firing as true all the time. However, even after I omitted it (and the OR node), it still doesn’t work sadly :frowning: I tested it with an array 1-2-0-0-0, then compared it to 0-2-0-1-3, and it still fired true, even though one of the numbers was 3 instead of a 0

Again, for that please read the Edit in my original Answer. With that fix, the accepted Null Works.

Thank you, I fixed that like you said, but the whole thing still doesn’t work, same thing as I wrote in my previous comment. 1-2-0-0-0 compared to 0-2-0-1-3 should fire false, but it fires true.

Funny that you say that because it works perfectly.

I tested some more and it didn’t work again. In array 1 I put in 0-2-1-1-3, and in array 2 I put 1-2-3-0-0. This should have fired false, but it fired true.
I have it set up the same way as you do:

Does your project implement c++? I forgot this from BP’s side: you should this from For Loop Inverse (starting from the last index). If I write this exact code on C++ with a for loop starting from the heap, it works perfectly. If you want to do it on Blueprint, you’ll have to write a For Loop from Last Macros since the Engine doesn’t provide one by default (some marketplace plugins do, though).

the code for the loop would be :

TArray<int> FlushedArray1 = Array1;
TArray<int> FlushedArray2 = Array2;
bool Temp = true;
int TempInt = -1;
for (int X = FlushedArray1.Num() - 1; Temp && (X >= 0); X--)
{
    TempInt = FlushedArray2.Find(FlushedArray1[X]);
	if (TempInt >= 0)
	{
		FlushedArray1.RemoveAt(X);
		FlushedArray2.RemoveAt(X);
	}
	else
	{
		Temp = false;
	}
	
}

This is without Accept Null option since I don’t think you’re going to be using it much.

It doesn’t. I’m not sure what you mean. I’m not that advanced in UE… :confused:
I had another idea though - what if I sort both arrays first from lowest to biggest number (so 3-2-0-1-0 would be reorganized into 0-0-1-2-3 and so on), and then compare them if they’re exactly the same?

I mean, that would work. However, you’d need the arrays to always have the exact same amount of items otherwise it would always return false. If you wanted a handle for differently sized arrays, you’d have to compare them int by int to what their reach is. If Array1.Num() = 5, and Array2.Num() = 2, then see if Array2’s sorted match Array1’s first two indexes.

That’s not an issue. Both arrays are always exactly 5 items long.

So since my arrays are always the same lenght, I solved it like this:

Thanks for the other tips though!