A prolog program to group cities
Please I need help here, it's an assigment
A prolog program that shows which cities are in south-
east of Nigeria. Here are the cities (abraka, oyo, awka,
orlu, markurdi, jalingo, owerri, aba, mushin, okigwe).
abraka (city not in south-east)
oyo (city not in south-east)
awka (city in south-east)
orlu (city in south-east)
markudi (city not in south-east)
jalingo (city not in south-east)
owerri (city in south-east)
aba (city in south-east)
mushin (city not in south-east)
okaigwe (city in south-east)
Please I don't know exactly what to开发者_StackOverflow中文版 do. Thanks for any
help.
One of the first things you shall do with a (prolog) problem is to choose a suitable representation for your data according to what queries you will need.
In this case, you will need to have a predicate like is_city_in_south_east(City). Therefore, you could represent your data as:
is_city_in_SOuth_east(abraka).
is_city_in_south_east(awka).
city_is_not_in_south_east(oyo).
....
however, this representation is too specific. something more general would be
city_location(abraka, south_east).
city_location(awka).
city_location(oyo, not_south_east).
I assumed that the
abraka (city not in south-east)
oyo (city not in south-east)
awka (city in south-east)
orlu (city in south-east)
markudi (city not in south-east)
jalingo (city not in south-east)
owerri (city in south-east)
aba (city in south-east)
mushin (city not in south-east)
okaigwe (city in south-east)
was just a human-readable representation of the database.
In case this is the actual input of your program you (in a text file for example) it's quite messy; I think that the easiest way is to build a mini-parser.
精彩评论