fork(2) download
  1.  
  2. fu([], _, _, []).
  3. fu(Lst, N, 0, Rez) :-
  4. append([_], Cdr, Lst),
  5. fu(Cdr, N, N, Rez).
  6. fu(Lst, N, K, Rez) :-
  7. append([A], Cdr, Lst),
  8. K1 is K - 1,
  9. fu(Cdr, N, K1, CdrRez),
  10. append([A], CdrRez, Rez).
  11. remove_each_nth(Lst, N, Rez) :-
  12. N1 is N - 1,
  13. fu(Lst, N1, N1, Rez).
  14.  
  15. main :-
  16. Lst1 = [1,2,3,4,5,6,7,8],
  17. remove_each_nth(Lst1, 3, Rez1),
  18. print(Rez1),
  19. remove_each_nth(Lst1, 2, Rez2),
  20. print(Rez2),
  21. remove_each_nth(Lst1, 1, Rez3),
  22. print(Rez3),
  23.  
  24. :- main.
Success #stdin #stdout 0.02s 6784KB
stdin
Standard input is empty
stdout
[1,2,4,5,7,8][1,3,5,7][]