Sunday, February 16, 2025

12. Write a Prolog program to implement reverse(List,ReversedList) that reverses lists.

 

Write a Prolog program to implement reverse(List,ReversedList) that reverses lists.

% Write a Prolog program to implement reverse(List,ReversedList) that reverses
% lists.


/* Reverse of the list. */

reverse([H|T],R):-
 length(T,L),
 L>0 ->
 (
  reverse(T,R1),
  /* write(R1), */
  R is H
 )
 ;
 R is H.
% Output
Prolog program to implement reverse(List,ReversedList) that reverses lists.
Prolog Program to reverse the elements in the list.

No comments:

Post a Comment

15. Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.

  Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list ...