How do I compare several lists with different items amount

0 favourites
  • 9 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • 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.

  • 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.

  • Up

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • How do you store and use your lists currently?

  • I will create an example for you understand what I am doing in a few minutes.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)