Prolog assignment help

Computer Science and ICT discussion, revision, exam and homework help.

This thread is sponsored by:
Announcements Posted on
Important: please read these guidelines before posting about exams on The Student Room 28-04-2013
Sign in to Reply
  1. lstirk's Avatar
    • New Member
    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
  2. iainmacn's Avatar
    • Overlord in Training
    • Location: London
    • Posts: 2,126
    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.
Sign in to Reply
Share this discussion:  
Article updates
Moderators

We have a brilliant team of more than 60 volunteers looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Reputation gems:
The Reputation gems seen here indicate how well reputed the user is, red gem indicate negative reputation and green indicates a good rep.
Post rating score:
These scores show if a post has been positively or negatively rated by our members.