Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write a predicate 'everyother' which will remove every other element .

Status
Not open for further replies.

rukman

Programmer
Nov 4, 2011
7
US
Write a predicate 'everyother' which will remove every other element in a list,
starting with the second element. List length can be odd or even.

e.g. ?- everyother([g,r,o,u,l,l,o,e,r,s,p],L).
L = [g,o,l,o,r,p];



i am trying like this
remove([_,_],[]).
remove([H,H|T],R):- not(member(H,T)),remove(T,R1),delete(H,R1,A).


Pls help needed urgent :(
 
If I understand, you must remove every even letter.
You have 2 base cases
Code:
everyother([],...).

everyother([A], ...).
And a rule
Code:
everyother([A, B | R], [A | ...]):-
      ......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top