Sunday, February 16, 2025

7. Write a Prolog program, remove-nth(Before, After) that asserts the After list is the Before list with the removal of every n’th item from every list at all levels.

 

Write a Prolog program, remove-nth(Before, After) that asserts the After list is the Before list with the removal of every n’th item from every list at all levels.

% Write a Prolog program, remove-nth(Before, After) that asserts the After list
% is the Before list with the removal of every n’th item from every list at all 
% levels.

/*delete a number in the list. */
delte(1,[_|T],T).
delte(P,[X|Y],[X|R]):-
 P1 is P-1,
 delte(P1,Y,R).

/* delete before and after. */
daltob(P,L,R):-
 P1 is P-1,
 delte(P1,L,R1),
 /* delete before. */
 delte(P,R1,R).
 /* delete after. */

% Output
Prolog Program to delete before and after of the nth element in the list.
Prolog Program to delete before and after of the nth element 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 ...