PDA

View Full Version : Compare 2 List's


Scott300
02-14-2009, 12:54 PM
Say I have 2 lists

list1- 1,1,2,2
list2- 1,1,2,2

Say I wanna check to see if the 2 lists have the exact same order of numbers so if list one is

list1- 1,1,2,2

and list 2 is

list2- 1,1,2,3

it will return false
but if its

list1- 1,1,2,2
list2- 1,1,2,2

Return True.

I have tried for awhile to solve this problem =/ would be great if any one could lend me a hand ^_^

ottar9919
02-14-2009, 03:30 PM
I am not sure, but you could try something like
If(List1[0]==List2[0]&&List1[1]==List2[1]...
and continue fore all of the numbers in the list.

Scott300
02-14-2009, 03:49 PM
The problem is, each time it checks it theres 1 more number in each list to check like first time it checks for a match, its

list1- 1
list2- 1

than next time it runs the check the list would be

list1- 1,2
list2- 1,2

and there really is no end how many items will be added to the list. Only thing is there will all ways be the same number of items on each list.

wongwanchap
02-15-2009, 02:06 AM
If (list1.length != list2.length) return false;
For (i=0;i<list1.length;i++) {
if(list1[i] != list2[i]) return false;
}
return true;


I think the logic should be like above.

Scott300
02-15-2009, 11:24 PM
I think the logic should be like above.

You can do that in alice?

wongwanchap
02-16-2009, 05:07 AM
Ok, but I didn't check it,

The function name is call "CompareList"

Scott300
02-16-2009, 06:30 PM
Works great =D
Didn't think it would work like that =)


Edit- Where is the size of function located at?

zonedabone
02-24-2009, 04:54 PM
I tried to make a function, but I can't do advanced list functions in a function:mad:, so it's a failure

DrJim
02-24-2009, 07:58 PM
I tried to make a function, but I can't do advanced list functions in a function:mad:, so it's a failure

I'm not sure what you mean by "advanced" list functions, but I think you can do most anything inside a function that you can in a method - with the major exception that an Alice function can't directly return a list.

You can "cheat" :) and get around the last by making the desired output list a global (world) variable and just have the function return a dummy value.

As an example, the attached program starts with the output as the single default value list and then changes it to list a and finally to list b. If you watch the world properties list as the program is running, you can see the list as it changes as well as it being "said."

Of course there are a lot of things you just can't do with lists - such as do a logical compare of different length lists - and a couple of the Alice 2.0 list tools don't work (search the forum for details). But this is true for both methods and functions.

Scott300
02-26-2009, 07:53 AM
One thing I couldent find is the "size of" function where is it located lol.

DrJim
02-27-2009, 12:08 AM
One thing I couldent find is the "size of" function where is it located lol.

It is a bit hidden :rolleyes: but it shows up when you drag and drop the list.

Scott300
02-27-2009, 08:35 AM
Oh wow =D Thanks