Working with SWI-Prolog. I have a list of ranks say:
rank(London, 3.5).
rank(New York, 3.5).
rank(Seattle, 2.3).
And I am trying to get my head around making a rule that prints/returns any facts with the same rank. So in this case it would come back with London & New York.
Here's what I've come up with so far, the only problem is the duplicates I get with it (although they make perfect sense with the current rule). Would using recursion somehow help this?
equal_rank(_):-
rank(U1, R1),
rank(U2, R2),
U1 \== U2,
R1 == R2,
print(R1), print(': '), print(U1), print(', '), print(U2), nl,
fail.
The output would be:
3.5: London, New York
3.5: New York, London
I just can't figure out how to stop that second line.