As one of the most iconic and recognisable structures in the world, the Eiffel Tower has been the inspiration for the creation of over 50 similar towers around the world. Most are not exact replicas, though there are many like it.
Given a database of Eiffel Tower replicas, containing following facts of the form replica_size(Name, Size)
, replica_country(Name, Country)
and replica_place(Name, (X,Y))
giving the values the variable names suggest. Size
is given as a term of the form 1:Scale
.
replicas_in(Country, L)
: True if L
is a alphabetically sorted list of names of replicas in Country
top_replicates(SortedList)
: True if SortedList
is unified with a list of tuples of the form (Country, Count)
sorted by Count
and then by Country
alphabetically.map_replicas_countries(ReplicaNames, Countries)
: Maps a list of replica names to a list of countries where the replicas are located.Make use of built-in predicates like setof/3
, bagof/3
, maplist
, sort/4
.
?- replicas_in("China",List).
List = ["Eiffel Tower of Tiandu City Community (also called Tianducheng)", "Eiffel Tower of Window of the World", "Long Ta"].
?- top_replicaters(List).
List = [("USA", 9), ("Russia", 4), ("China", 3), (..., ...)|...].
?- map_replicas_countries(["Las Vegas Eiffel Tower", "Krasnoyarsk Eiffel Tower"], Countries).
Countries = ["USA", "Russia"].
To test your code, you can use this database1