Monday, July 17, 2023

13. 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.

 13. 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. 

evenlength:-

write('true --> even').

oddlength:-

write('true --> odd').

 

oddeven([_|T]):- length(T,L), L>=0 -> (  L1 is L+1,  L2 is mod(L1,2),  L2=:=0 ->evenlength  ;   oddlength ).




OUTPUT:

 

oddeven([5,8,9]).

true --> odd

1true

oddeven([5,8,6,9]).

true --> even

1true

 



No comments:

Post a Comment