20_09

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.

 Source Code :

 

/* 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 */

del(P,L,R):-

 length(L,L1),

 (

 P=:=1 ->

  P3 is P+1,

  delte(P3,L,R)

  ;

 P=:=L1 ->

  P3 is P-1,

  delte(P3,L,R)

  ;

  P1 is P-1,

  delte(P1,L,R1),

  /* Delete before */

  delte(P,R1,R)

  /* Delete after */

 ).

 

Output :

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

 

No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...