Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Lab Code: P1
- Problem: 11 - b
- Statement: Remove the first 3 occurences of an element from a list. If the element occurs less than 3 times, remove all its occurences.
- */
- remove([],_,[],_). %remove(list,elem,newlist,noOfOccurences)
- remove([El|T],El,T,Occ):-
- Occ > 1,
- remove(T,El,T,Occ),
- Occ = Occ -1.
- remove([H|T1],El,[H|T2],Occ):-
- not(H = El);
- not(Occ > 1),
- remove(T1,El,T2,Occ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement