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!

List Problems, need help, thank you.

Status
Not open for further replies.

alig84uk

Programmer
Nov 23, 2003
1
0
0
GB
hey ive got quite a few small problems which im sure people will be able to help with easy...im not too good at prolog as im used to java and C. All are based on lists, here goes:

-Previous-to(X,Y,Z) where x and y is an element of the list Z, and x comes before y.

-number-occurances(X,Y,Z) where x is an element of y, and z is the number of times it occurs.

-delete-all(X,Y,Z) where x is an element of list y and z is the obtained list after deleting all occurrences of x in y.

-delete-all-even(X,Y,Z) where x is an element of list y, and z is the list obtained by deleting all X in Y if x is an even number, or only the first occurrence if it is an odd number.

Thank you for all your help, i really do appreciate it so much, and hopefully i will begin to understand prolog with peoples help.

Cheers
Andrew
 
Not sure i understand exactly what your problem is. I can see what the lists are all about, but where are you stuck at?
 
General hint: make sure you dig recursion

Hint on previous-to:

It's obviously true if X is the head of a list and Y is a member of the list. So you must first figure out a member predicate, then reduce Z to the point where X is the head.

Hint on number-occurences:

number-occurences(X,[],0). Build from that.

Hint on delete-all and delete-all-even. see elsewhere in this forum for select and select_all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top