Prolog assignment help
Computer Science and ICT discussion, revision, exam and homework help.
| Announcements | Posted on | |
|---|---|---|
| Important: please read these guidelines before posting about exams on The Student Room | 28-04-2013 | |
-
Prolog assignment help
Hey guys, i have an assignment due in for next week, and im really struggling to get my head around it! Ive looked through notes and books and just dont understand it. The coursework is about network manipulations and i have 15 questions to anwser!
The first question is this. Define a predicate equal/1 for finding out in a list of string constants whether all the lists entries are the same. Example :
?- equal ([dog,dog,dog,dog]).
Yes
?- equal ([dog,dog,cat,dog,cat]).
No
Can anyone help me out and give me some sort of starting point. Also does anyone know any good tutorials?
Thanks -
Re: Prolog assignment help
Well, it's liekly to be recursive, so I'd suggest comparing the first element in the list with the head of the rest of the list. If that doesn't match, return a fail, otherwise keep going down the list (recursively - chopping the first element off) until you reach an empty list - when you return true.