If you execute the following query, Left and Right will be bound to two lists that, when concatenated together, result in [1,2,3,4,5]:
?- append(Left, Right, [1,2,3,4,5]).
The above query admits 6 solutions (Left being empty, the list [1], the list [1,2], etc.). You can constrain the query by saying that Left exactly has three elements:
?- length(Left, 3), append(Left, Right, [1,2,3,4,5]).
Left = [1, 2, 3]
Right = [4, 5]
This has only one solution.
The rotation consists in producing a list where the Left part is on the right of the Right list:
?- length(Left, 3),
append(Left, Right, [1,2,3,4,5]),
append(Right, Left, Result).
Left = [1, 2, 3]
Right = [4, 5]
Result = [4, 5, 1, 2, 3]
The first predicate you need to write is thus:
rotate_left(List, Offset, Rotated) :-
length(Left, Offset),
append(Left, Right, List),
append(Right, Left, Rotated).
Then you can apply this predicate on a list of lists.
NB. you may consider using this version instead:
rotate_left(List, Offset, Rotated) :-
append(Left, Right, List),
length(Left, Offset),
append(Right, Left, Rotated).
It is a bit better because it allows Offset to be variable:
[eclipse 2]: rotate_left([a, b, c, d], N, [c, d, a, b]).
N = 2
Yes (0.00s cpu, solution 1, maybe more) ? ;
No (0.00s cpu)
With the original version, length(Left, N) has both its arguments variable, and it keeps producing answers with longer and longer lists.