sumsegs(L,N,[Sum]) :-
    length(L,Len),
    Len =< N,
    sumlist(L,Sum).

sumsegs(L,N,R) :-
    length(L,Len),
    Len > N,
    length(First,N),
    append(First,Rest,L),
    sumlist(First,Sum),
    sumsegs(Rest,N,SumRest),
    append([Sum],SumRest,R).

sumsegs2(L,N,Sum) :-
    length(L,Len),
    0 < Len, Len < N,
    sumlist(L,Sum).
    
sumsegs2(L,N,Sum) :-
    length(FirstN,N),
    append(FirstN,_,L),
    sumlist(FirstN,Sum).

sumsegs2(L,N,Sum) :-
    length(Drop,N),
    append(Drop,NextN,L),
    sumsegs2(NextN,N,Sum).

revsegs(L,N,R) :-
    length(L,Len),
    Len =< N,
    reverse(L,R).

revsegs(L,N,R) :-
    length(L,Len),
    Len > N,
    length(First,N),
    append(First,Rest,L),
    reverse(First,RevFirst),
    revsegs(Rest,N,RevRest),
    append(RevFirst,RevRest,R).

