Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with Prolog!!

Options
  • 13-11-2007 7:43pm
    #1
    Registered Users Posts: 13,746 ✭✭✭✭


    this is a sample question and ive no idea how to do it!
    ive drawn a complete blank and cant for the life of me make sense of the notes!!

    domain: dublin and cork are cities in Ireland. Berlin, Leipzig and Bonn are cities in Germany. Bern, Zurich are cities in Switzerland. Washington and New York are cities in the USA. Toronto and Vancouver are cities in Canada. Dublin, Berlin, Bern, Washington and Toronto are capital cities. Ireland, Germany and Switzerland are in Europe. USA and Canada are in North America.

    allcapitals/1 write a predicate allcapitals/1 which takes a list as argument and succeeds if every member of the list is a capital city.

    citiesoncontinent write a predicate citiesoncontinent/2 which succeeds if every member of arg1 is on the continent arg2.

    capitalof/2 write a predicate capitalof/2 which succeeds if every member of arg1 is a capital of arg2. Note that the order of the elements in each list (arg1 and arg2) does not matter.
    :confused:


Comments

  • Registered Users Posts: 6,240 ✭✭✭hussey


    Have not done this in years - so I could get some syntax wrong

    First define the elements (a cut down version here)
    city(dublin)
    city(cork)

    cityOf(ireland, dublin)
    cityOf(ireland, cork)

    capital(dublin)

    belongsTo(europe, ireland)

    all capitals - since you are looping through a list - you need two conditions - empty list and condition

    allcapital([]). - true if last of list
    allcapital([ H | L] ) :- capital(H), allcapital(L).
    so in english if the Head of the list is a capital, call the condition with rest of List

    citiesoncontinent - loop is similar to over - but the capital(X) bit is : cityof(Arg1, C), belongsto(Arg2, C)

    number 3 you can do yourself - but is simple - I assume it is two list though


  • Registered Users Posts: 13,746 ✭✭✭✭Misticles


    does anyone have the full answer, thanks :)


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Misticles wrote: »
    does anyone have the full answer, thanks :)
    No, because that would be a clear violation of the No Homework rule.


  • Registered Users Posts: 13,746 ✭✭✭✭Misticles


    its not homework! its a question i had last week on an exam!!!


Advertisement