How do I compare several lists with different items amount

Get help using Construct 2

Post » Sun Oct 23, 2016 10:15 am

I need to compare several lists (more than 20) and each one of these lists could have from 1 to 10 items and these items are not in the order. At the final I just need to know how many of these lists are equal or not. (e.g. 20 lists: 10 equals/10 unique). I have looked some examples but they compare all the items regardless of the lists

Thanks in advance.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Mon Oct 24, 2016 10:57 am

Could someone help me with this issue, please? My project is almost ready and I just need to verify the lists at the end. If the lists are not the best solution, I'm open to suggestions. Just to exemplify: I'm using more than 20 lists with numbers that represent a type of the fruit and its amount (e.g. 1- 4) and I need to check at the end how many lists are equals (same number of items and the same combinations independently of the order) or not. (e.g.: list1(1-4, 2-3) = list2 (2-3, 1-4) but not equal to list3 (1-4,2-3,4-9)). Thanks in advance for any help.
Last edited by RBuster on Tue Oct 25, 2016 2:35 pm, edited 1 time in total.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Tue Oct 25, 2016 2:34 pm

Up
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Tue Oct 25, 2016 5:57 pm

Put all the arrays you want to compare into two families: listA,listB

The first step is to compare every two pair of arrays, and check if their sizes are the same. Here's a way to do that:

for "a" from 0 to listA.count-2
system: pick instance # loopindex("a") of listA
for "b" from loopindex("a")+1 to listB.count-1
system: pick instance # loopindex("b") of listB
system: compare listA.width = listB.width
--- sub event

The sub event is how you compare the values in the two lists. If you sort the lists then it's simple and you can compare each index of each pair of lists. If you don't want the lists' values to be sorted then then you can copy the lists using asJson to two different arrays and sort them first.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Oct 25, 2016 6:09 pm

@R0J0hound

Thanks for the reply. My data will be located in 25 lists aprox. (with 1 to 10 items per list) and I don't know why I need to populate an array with this data. Actually, I thought that I did not need to insert this information into the arrays.
Last edited by RBuster on Wed Oct 26, 2016 9:31 am, edited 1 time in total.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Tue Oct 25, 2016 7:19 pm

How do you store and use your lists currently?
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Oct 25, 2016 7:37 pm

I will create an example for you understand what I am doing in a few minutes.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Tue Oct 25, 2016 9:51 pm

Here's an example of it in action:
https://dl.dropboxusercontent.com/u/542 ... lists.capx

Basically look at every pair of lists with two loops like I mentioned above. Families can be used to pick both at once or you can just pick each individually like in the capx. In the capx I copy the list over to an array, and then sort the array. Next if the number of items is the same we can compare each item and see if they're equal, and if they are you can mark those lists as no unique.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Oct 25, 2016 10:30 pm

R0J0hound wrote:Here's an example of it in action:
https://dl.dropboxusercontent.com/u/542 ... lists.capx

Basically look at every pair of lists with two loops like I mentioned above. Families can be used to pick both at once or you can just pick each individually like in the capx. In the capx I copy the list over to an array, and then sort the array. Next if the number of items is the same we can compare each item and see if they're equal, and if they are you can mark those lists as no unique.



A BIG THANK YOU!!! I will analyse each line of this capx to really understand what I would have to have done to create it. Thanks a lot for each millisecond of the time that you have spent on it.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041


Return to How do I....?

Who is online

Users browsing this forum: lukewasthefish, Nicolas951, tarek2 and 6 guests