I am working on an assignment with prolog which involves an airport database (it has airport cities, and flight links which includes airport tax and duration time) and the first question involves queries. We are supposed to write a Prolog query to answer a question, I already know how to answer the question the problem is Prolog is outputing more information then I want. The query I wrote is:
flight(X,_,Y,_,N), N > 180.
Basically all it does is list out all cities (X is origin flight, and Y is the destination flight and N is duration). I want X and Y but I do not want N. The only way I can think of getting this to work is by wrapping this query in a rule and just having it display X and Y, but since we are not supposed to write rules I am not sure how to get around this. I do not really want an explicit answer just maybe a hint or something.
Where possible I prefer use expressions to compact IO
?- forall((flight(X,_,Y,_,N), N > 180),
writeln((x=X,y=Y))).
for instance, with a different generator
?- forall((member(X,"12"),member(Y,"ab")),writeln((x=X,y=Y))).
x=49,y=97
x=49,y=98
x=50,y=97
x=50,y=98
true.
Of course, to properly indent tables format/2 will do much better...
edit maybe I misunderstood the question, supposing you already considered
query(X,Y) :-
flight(X,_,Y,_,N), N > 180.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With