Goto https://www.stucuk.netGoto https://www.atlanticaonlinewiki.comGoto https://www.game-requirements.com


Menu


It is currently Sun Aug 19, 2018 1:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Find the smallest list
PostPosted: Wed Aug 19, 2009 12:40 am 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
I don't know if this is too trivial to post but I'll give it a try.
This is a function which finds the smallest list from a collection of several lists. The lists must be put into one huge list (the "list_of_lists" thingy). If "I_want_the_list" is set to "true" the function returns the smallest list (or, if more lists are of the same size, returns a list with all the smallest lists). If it's set to "false", the function returns the size of the smallest list as a number.

Code:
Export Function FindSmallestList(list_of_lists, I_want_the_list);
     var smallest, a, b, a_list, b_list, candidates, c;
     begin
          if list_of_lists = 0 or not (I_want_the_list = true or I_want_the_list = false) then
               begin
                    result = 99999;
                    exit;
               end;
          smallest = 99999;

          for a = 1 to list_of_lists - 1 do
               begin
                    a_list = list_of_lists[a];
                    if not IsList(a_list) then a_list = 1;

                    b = a;
                    repeat
                    b = b + 1;

                    b_list = list_of_lists[b];
                    if not IsList(b_list) then b_list = 1;

                    if a_list < b_list then
                         begin
                              if a_list < smallest then
                                   if I_want_the_list then
                                        smallest = list_of_lists[a]
                                   else
                                        smallest = a_list+0;
                         end
                    else
                         if a_list > b_list and b_list < smallest then
                              if I_want_the_list then
                                   smallest =  list_of_lists[b]
                              else
                                   smallest = b_list+0;

                    if I_want_the_list then
                         if not IsList(smallest) then
                              begin
                                   candidates = [];
                                   for c in list_of_lists do
                                        if c+0 = smallest+0 then candidates = Insert(candidates, 1, c);
                                   result = candidates;
                                   exit;
                              end;
                    if not I_want_the_list then
                        if smallest = 1 then
                             begin
                                  result = smallest;
                                  exit;
                             end;
                    until b = list_of_lists;
               end;

          if I_want_the_list then
               begin
                    candidates = [];
                    for c in list_of_lists do
                         if c+0 = smallest+0 then candidates = Insert(candidates, 1, c);
                    result = candidates;
               end
          else result = smallest;
     end;
Export Function IsList(value);
     var a, number;
     begin
          number = 0;
          for a in value do
               begin
                    number = number + 1;
                    if number > 1 then
                         begin
                              result = true;
                              exit;
                         end;
               end;
          result = false;
     end;


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy