Question

J'essayais ce programme Palindrome dans Prolog, la logique fonctionne mais l'écriture ne fonctionne pas. Alors, quel est le problème du code?

palin (list1): - findRev (list1, [], list2), compare (list1, list2).

findrev([],List1,List1).

findrev([X|Tail],List1,List2):-
    findrev(Tail,[X|List1],List2).

compare([],[]):-
    write("\nList is Palindrome").

compare([X|List1],[X|List2]):-
    compare(List1,List2).

compare([X|List1],[Y|List2]):-
    write("\nList is not Palindrome").

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top