[GAP Forum] Comparison of Length of Lists of list

Siddiqua Mazhar (PGR) s.mazhar at newcastle.ac.uk
Fri Oct 10 13:11:50 BST 2014


Dear Sir/Madam,

If I have a list let say a:=[[1,2,3],[4,5],[6,7,8,9],[10,11,12,],[13,14],[15,16,17,18]];

I want to find the list of maximum length in it, or collection of list of max length from above

For instance,  result:=[[6,7,8,9],[15,16,17,18]]; how can i find this result?

here is one algorithm that I tried, I know something is wrong in here. this is why it is not compiling

>Comparison:=function(a)
>local i,k;
>k:=[];
>  for i in [1..Length(a)] do
>   repeat 
>     if Length(a[i])<Length(a[i+1]) then
>         Add(k,a[i+1]);
>      else
>          Add(k,a[i]);
>     fi;
>   until (i+1)=Length(a);
>  od;
>return k;
>end;

Many thanks.

Kind regards
Siddiqua


More information about the Forum mailing list