[GAP Forum] Sublists of list

Stephen Linton steve.linton at st-andrews.ac.uk
Thu Oct 2 16:06:41 BST 2014


There is no built-in function that does exactly what you want, so you will need to write a short program to do this.  There are lots of ways to do that, some are shorter than others, some more readable, some more efficient.

Here is one solution:

sl := function ( l )
    local  ll;
    ll := Concatenation( l, l );
    return Concatenation( List( [ 1 .. Length( l ) ], function ( i )
              return List( [ i + 1 .. i + Length( l ) - 2 ], function ( j )
                      return ll{[ i .. j ]};
                  end );
          end ) );
end;

Then 

sl2 := l->Concatenation(List(l,sl));

I suggest you have a look at the reference manual especially chapter 

http://www.gap-system.org/Manuals/doc/ref/chap0.html

especially chapters 4 and 21. If you need further assistance you can contact GAP support on
support at gap-system.org.

	Steve

On 2 Oct 2014, at 15:13, Siddiqua Mazhar (PGR) <s.mazhar at newcastle.ac.uk> wrote:

> Dear Sir/Madam,
> 
> My question is, if I have a list like
> 
> a:=[[1,2,4,6,11],[12,23,19,17,15]]
> 
> then how can I find the sublists of this list in GAP that are in the same order of the elements as it has been placed in the list. For instance I want to find the result in this form
> 
> result:= [1,2],[2,4],[4,6],[6,11],[11,1],[1,2,4],[2,4,6],[4,6,11],[6,11,1],[11,1,2],[1,2,4,6],[2,4,6,11],[12,23],[23,19],[19,17],[17,15],[15,12],[12,23,19],[23,19,17],[19,17,15],[17,15,12],[15,12,23][12,23,19,17],[23,19,17,15];
> 
> 
> Kind regards
> Siddiqua
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum




More information about the Forum mailing list