Tuesday 1 November 2016

Write a Prolog program to implement palindrome(List).

% Write a Prolog program to implement palindrome(List).

% append is the inbuilt function.

palind([]):- write('palindrome').
palind([_]):- write('palindrome').
palind(L) :-
 append([H|T], [H], L),
 palind(T)
 ;
 write('Not a palindrome').

% Output
Prolog program to implement palindrome(List).
Prolog program to implement palindrome(List).

1 comment:

  1. can you explain what append([H|T], [H], L) is doing? I understand that you're removing the first and last element of the array, but could you break this down

    ReplyDelete