[GAP Forum] Comparison of Length of Lists of list
Siddiqua Mazhar (PGR)
s.mazhar at newcastle.ac.uk
Fri Oct 10 13:59:02 BST 2014
Dear Sir/Madam,
Here I made changes in my previous email, sorry for inconvinience
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
>Comparison:=function(a)
>local i,k;
>k:=[];
> for i in [1..(Length(a)-1)] do
> if Length(a[i])<Length(a[i+1]) then
> Add(k,a[i+1]);
> elif not a[i] in k then
> Add(k,a[i]);
> fi;
> od;
>return k;
>end;
This program works, however , what if two list are of same length next to each other?
for instance a:=[[1,2,3],[4,5],[6,7],[8,9,10]]?
want this result:=[1,2,3],[8,9,10]
or if a:=[[1,2],[3,4],[5,6]] in this case the result wouldl be the same as a because every list are of same length.
Many thanks.
Kind regards
Siddiqua
More information about the Forum
mailing list