Gh0sT
Gh0sT

Reputation: 13

Function return false - Swi-Prolog

I am currently working on my proyect for my Programming classes. The work is to resolve a Skyline problem. A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. So, basically, you take a list of buildings with 3 parameters each (initial position,final position, height) and you have to return the coordinates of the Skyline.

I have two base cases. First one is used when the list is empty. Second one is if there is only one building and the last one is used when I have two or more buildings in the list. The function 'divide' receives a list of buildings and returns two lists of buildings.

My problem is:

divide([],[],[]).
divide([C|[]],[C|ed(X1,X2,H1)]):-
   divide([],ed(X1,X2,H1),[]).
divide([ed(X1,X2,H1),ed(Y1,Y2,H2)|L],L1,L2):-
   L1 = [ed(X1,X2,H1)|L1],
   L2 = [ed(Y1,Y2,H2)|L2],
   divide(L,L1,L2).

When I run the function 'divide' on the console it returns false as answer instead of returning a list. I just can't figure out what is wrong or where the problem might be. It should return two lists, not a 'false'.

An example:

?- divide([(1,2,3),(2,3,4),(1,4,5),(6,2,4)],X,Y).

false.

Any ideas? Sorry for the bad english and thanks.

Upvotes: 1

Views: 749

Answers (1)

false
false

Reputation: 10102

Always look at the warnings your Prolog system produces. If you ignore them, don't be surprised to fail. Here is another error:

divide([C|[]],[C|ed(X1,X2,H1)]):-
                 ^^^^^^^^^^^^

This is not a well formed list.

Upvotes: 3

Related Questions