Monday, July 17, 2023

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.

 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.


del(1,[_|T],T).

del(P,[X|Y],[X|R]):-

 P1 is P-1,

 del(P1,Y,R).



dalpos(P,L,R):-

 P1 is P-1,

 del(P1,L,R1),

 del(P,R1,R).


OUTPUT:


del(2,[10,20,30,40],X).

X = [10, 30, 40]

Next101001,000 Stop


No comments:

Post a Comment