New programming languages

Moderators: None (Apply to moderate this forum)
Number of threads: 111
Number of posts: 329

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
prolog Posted by 001 on 1 Feb 2004 at 12:39 PM
I have this prolog database but i cant seem to be able to
implement the following goals,
-listing all features adjacent to:
Indian ocean
Mediterranean sea
Red sea
Atlantic
All landlocked countries
Could someone help!!!!

Code
Predicates
country(symbol)
island(symbol)
sea(symbol)
lake(symbol)
ocean(symbol)
landlocked(symbol)
adjacent(symbol,symbol)
borders(symbol,symbol)
waterbody(symbol)

Clauses
country(morocco).
country(algeria).
country(tunisia).
country(libya).
country(egypt).
country(sudan).
country(chad).
country(niger).
country(mali).
country(mauritania).
country(cape_verde).
country(senegal).
country(gambia).
country(guinea_bissau).
country(guinea).
country(sierra_leone).
country(liberia).
country(ivory_coast).
country(burkina_faso).
country(ghana).
country(togo).
country(benin).
country(nigeria).
country(cameroon).
country(central_african_republic).
country(equatorial_guinea).
country(gabon).
country(congo).
country(democratic_republic_congo).
country(rwanda).
country(burundi).
country(kenya).
country(uganda).
country(tanzania).
country(ethiopia).
country(eritrea).
country(djibouti).
country(somalia).
country(angola).
country(zambia).
country(malawi).
country(zimbabwe).
country(mozambique).
country(botswana).
country(namibia).
country(swaziland).
country(lesotho).
country(south_africa).

island(madagascar).
island(comoros).
island(mauritius).
island(reunion).

sea(red).
sea(mediterranean).

ocean(atlantic).
ocean(indian).

lake(malawi).
lake(tanganyika).
lake(victoria).





adjacent(egypt,red).
adjacent(sudan,red).
adjacent(eritrea,red).
adjacent(djibouti,red).
adjacent(somalia,red).
adjacent(mediterranean,red).
adjacent(indian,red).

adjacent(kenya,indian).
adjacent(tanzania,indian).
adjacent(mozambique,indian).
adjacent(madagascar,indian).
adjacent(mauritius,indian).
adjacent(comoros,indian).
adjacent(mozambique,indian).
adjacent(south_africa,indian).
adjacent(reunion,indian).
adjacent(red,indian).
adjacent(atlantic,indian).


adjacent(south_africa,atlantic).
adjacent(namibia,atlantic).
adjacent(angola,atlantic).
adjacent(congo,atlantic).
adjacent(gabon,atlantic).
adjacent(cameroon,atlantic).
adjacent(nigeria,atlantic).
adjacent(benin,atlantic).
adjacent(togo,atlantic).
adjacent(ghana,atlantic).
adjacent(ivory_coast,atlantic).
adjacent(liberia,atlantic).
adjacent(sierra_leone,atlantic).
adjacent(guinea_bissau,atlantic).
adjacent(gambia,atlantic).
adjacent(senegal,atlantic).
adjacent(cape_verde,atlantic).
adjacent(mauritania,atlantic).
adjacent(morocco,atlantic).
adjacent(guinea,atlantic).
adjacent(equatorial_guinea,atlantic).
adjacent(mediterranean,atlantic).


adjacent(morocco,mediterranean).
adjacent(libya,mediterranean).
adjacent(egypt,mediterranean).
adjacent(algeria,mediterranean).
adjacent(tunisia,mediterranean).

waterbody(lake).
waterbody(sea).
waterbody(ocean).



borders(A,B):-adjacent(A,B).
borders(A,B):-adjacent(B,A).
borders(B,A):-adjacent(A,B).
borders(B,A):-adjacent(B,A).

borders(kenya,victoria).
borders(uganda,victoria).
borders(tanzania,victoria).

Goal
landlocked(X):- country(X),not(adjacent(X,_)).
/* landlocked(X).All landlocked couintries*/

/* adjacent(X,atlantic).Features adjacent to Atlantic Ocean*/

/* adjacent(X,red).oceans,lakes,countries,seas,islands*/

adjacent(victoria,X).







Report
Re: prolog Posted by novamoon on 24 Jul 2004 at 9:32 AM
I think that your mistake is in your goal. Notice some points:
1. In goal you can not make any rules.
2.You should use clauses which have one unknown parameter at least. Otherwise the prolog gives you 'Yes' or 'No' answer.
3.'landlocked' is a base predicates. Therefore must added in the clauses.

Predicates
country(symbol)
island(symbol)
sea(symbol)
lake(symbol)
ocean(symbol)
landlocked(symbol)
adjacent(symbol,symbol)
borders(symbol,symbol)
waterbody(symbol)

Clauses
landlocked(mali).
country(morocco).
country(algeria).
country(tunisia).
country(libya).
country(egypt).
country(sudan).
country(chad).
country(niger).
country(mali).
country(mauritania).
country(cape_verde).
country(senegal).
country(gambia).
country(guinea_bissau).
country(guinea).
country(sierra_leone).
country(liberia).
country(ivory_coast).
country(burkina_faso).
country(ghana).
country(togo).
country(benin).
country(nigeria).
country(cameroon).
country(central_african_republic).
country(equatorial_guinea).
country(gabon).
country(congo).
country(democratic_republic_congo).
country(rwanda).
country(burundi).
country(kenya).
country(uganda).
country(tanzania).
country(ethiopia).
country(eritrea).
country(djibouti).
country(somalia).
country(angola).
country(zambia).
country(malawi).
country(zimbabwe).
country(mozambique).
country(botswana).
country(namibia).
country(swaziland).
country(lesotho).
country(south_africa).

island(madagascar).
island(comoros).
island(mauritius).
island(reunion).

sea(red).
sea(mediterranean).

ocean(atlantic).
ocean(indian).

lake(malawi).
lake(tanganyika).
lake(victoria).





adjacent(egypt,red).
adjacent(sudan,red).
adjacent(eritrea,red).
adjacent(djibouti,red).
adjacent(somalia,red).
adjacent(mediterranean,red).
adjacent(indian,red).

adjacent(kenya,indian).
adjacent(tanzania,indian).
adjacent(mozambique,indian).
adjacent(madagascar,indian).
adjacent(mauritius,indian).
adjacent(comoros,indian).
adjacent(mozambique,indian).
adjacent(south_africa,indian).
adjacent(reunion,indian).
adjacent(red,indian).
adjacent(atlantic,indian).


adjacent(south_africa,atlantic).
adjacent(namibia,atlantic).
adjacent(angola,atlantic).
adjacent(congo,atlantic).
adjacent(gabon,atlantic).
adjacent(cameroon,atlantic).
adjacent(nigeria,atlantic).
adjacent(benin,atlantic).
adjacent(togo,atlantic).
adjacent(ghana,atlantic).
adjacent(ivory_coast,atlantic).
adjacent(liberia,atlantic).
adjacent(sierra_leone,atlantic).
adjacent(guinea_bissau,atlantic).
adjacent(gambia,atlantic).
adjacent(senegal,atlantic).
adjacent(cape_verde,atlantic).
adjacent(mauritania,atlantic).
adjacent(morocco,atlantic).
adjacent(guinea,atlantic).
adjacent(equatorial_guinea,atlantic).
adjacent(mediterranean,atlantic).


adjacent(morocco,mediterranean).
adjacent(libya,mediterranean).
adjacent(egypt,mediterranean).
adjacent(algeria,mediterranean).
adjacent(tunisia,mediterranean).

waterbody(lake).
waterbody(sea).
waterbody(ocean).



borders(A,B):-adjacent(A,B).
borders(A,B):-adjacent(B,A).
borders(B,A):-adjacent(A,B).
borders(B,A):-adjacent(B,A).

borders(kenya,victoria).
borders(uganda,victoria).
borders(tanzania,victoria).

Goal
landlocked(X), country(X),not(adjacent(X,_)),
/* landlocked(X).All landlocked couintries*/

/* adjacent(X,atlantic).Features adjacent to Atlantic Ocean*/

/* adjacent(X,red).oceans,lakes,countries,seas,islands*/

adjacent(victoria,X).


Now it run without problems. I hope that's clear, if you have some other problems you can contact me.
My E_mail: novapar@yahoo.com
<Parvin Abedi>



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.