TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

compare two lists

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Fri May 15, 2015 5:15 pm    Post subject: compare two lists Reply with quote

How can I prove if two lists are equal?

list 1

{{1}{a}{2}{b}}

list 2 same as list1

{{1}{a}{2}{b}}

#if "{{1}{a}{2}{b}}"=="{{1}{a}{2}{b}}" seems not working.

I need to sort varibles by list sort before comparing, so have to use list
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Sat May 16, 2015 7:35 am    Post subject: Reply with quote

done


#if $list1[1]==$list2[1] && $list1[2]==$list2[2] && $list1[3]==$list2[3]
Back to top
View user's profile Send private message
LokiChaos



Joined: 27 Oct 2009
Posts: 61

PostPosted: Sat May 16, 2015 1:45 pm    Post subject: Reply with quote

For a more generic test, for any length lists:
Code:

#function {listEquals} {
   #var __testlist[1] {%1};
   #var __testlist[2] {%2};
   #var result 1;
   #nop Equal lists must be same length;
   #if {"&{__testlist}[1][]" != "&{__testlist}[2][]"} {
      #var result 0;
   };
   #else {
      #nop Iterate over members, if a non-equal is found lists don't match;
      #foreach {&{__testlist}[1][]} {__idx} {
         #if {"${__testlist}[1][${__idx}]" != "${__testlist}[2][${__idx}]"} {
            #var result 0;
            #break;
         };
      };
   };
   #unvar __idx;
   #unvar __testlist;
}


Example:
Code:

#var a {{1}{a}{2}{b}{3}{c}};
#var b {{1}{a}{2}{b}{3}{c}};
#var c {{1}{a}{2}{b}{3}{d}};
#var d {{1}{a}{2}{b}{3}{c}{4}{d}};


#showme TEST;
#showme a == b;
#showme @listEquals{ {$a} {$b} };
#showme a == c;
#showme @listEquals{ {$a} {$c} };
#showme a == d;
#showme @listEquals{ {$a} {$d} };


Should give 1, 0, 0 respectively.
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Sat May 23, 2015 3:05 pm    Post subject: Reply with quote

Thanks,

it's quite good
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group