I am trying to write a predicate removeRotations. The idea is that I have a List of the following form:
[[1, 2, 3], [2, 1, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]]
It takes each element, rotates it using
append(T,[H],Rotation)
It then checks the rotation if it is a member of the whole list. If Yes, then it is removed from the List using
select(Rotation,[H|T],NewList)
Similarly, the same is going to happen to the remaining List. In the end it should return the List that has no rotations.
Going through each H of List Rotation Stays/Remove
[1,2,3] [2,3,1] [1,2,3] Stays ([2,3,1] not in List)
[2,1,3] [1,3,2] Remove [1,3,2]
[1,3,2] [3,2,1] Remove [3,2,1]
[3,1,2] [1,2,3] Remove [1,2,3]
[3,2,1] [2,1,3] Remove [2,1,3]
?-removeRotations([[1, 2, 3], [2, 1, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]],List).
List = [[3,1,2]]
?-removeRotations([[1, 2, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]],List).
List = [[1,3,2],[3,1,2]]
My attempt is just bad, I am unsure what to do when H is not a member?
rr([H|T],[H1|T1],W):-
r([H|T],[H1|T1],W).
r([],_,[]):-!.
r([H|T],[H1|T1],[W|L]):-
r1(H,[H1|T1],W),
r(T,[H1|T1],L).
r1([H|T],[H2|T2],W):-
append(T,[H],Rot),
(\+member(Rot,[H2|T2])-> W=[];select(Rot,[H2|T2],W)).
?-rr([[1, 2, 3], [2, 1, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]],[[1, 2, 3], [2, 1, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]],W).
W = [[], [[1, 2, 3], [2, 1, 3], [3, 1, 2], [3, 2, 1]], [[1, 2, 3], [2, 1, 3], [1, 3, 2], [3, 1, 2]], [[2, 1, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]], [[1, 2, 3], [1, 3, 2], [3, 1, 2], [3, 2, 1]]]
false
Any help will be appreciated.