Sunday, February 16, 2025

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 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 of even or
% odd length respectively.

evenlength:-
 write('true --> even').
oddlength:-
 write('true --> odd').

oddeven([H|T]):-
 length(T,L),
 L>=0 ->
 (
  L1 is L+1,
  L2 is mod(L1,2),
  L2=:=0 ->
   evenlength
  ;
   oddlength
 ).
% Output
Prolog program to implement two predicates evenlength(List) and oddlength(List).
Prolog program to implement two predicates evenlength(List) and oddlength(List).

1 comment:

  1. University students often have to manage lectures, projects, exams, and several assignments at the same time. For those facing difficult coursework, assignment help in adelaide can offer useful academic guidance. Students can receive support with research, organisation, formatting, and understanding complex subjects. Having clear guidance makes it easier to approach assignments systematically and meet deadlines. It can also reduce academic pressure while encouraging students to develop stronger writing, research, and subject-specific skills throughout their university studies.

    ReplyDelete

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