Is there a way to test wether an arbitrary list is symmetric?
For example:
?- symmetric([a,b,b,a]).
true.
?- symmetric([a,b,c,a]).
false.
?- symmetric([a,a]).
true.
My attemp was to compare the first element to the last element and if they are equal to remove them and proceed with the rest of the list; otherwise fail. Succeed if the list has 2 elements and they are equal. Otherwise fail.
However "finding" the end of the list using this predicate is not really performant:
last(L,[L]).
last(L,[H|T]):-last(L,T).
Does anyone know of a good way to do this? Any help would really be appreciated!
Btw: I don't care for lists with an uneven amount of elements.