Answers Datalog practice questions
All are from book exercise 24.1.
- Part 1: ans(fno):- Flights(fno, "Madison", _, _, _, _)
- Part 2: ans(fno):- Flights(101, _, "Chicago", _ , _,
carrives), Flights(fno, "Chicago", _, depart, _), depart >
carrives, carrives + 1hr < depart
- Part 3: ans(fno):-Flights(fno, from, to, dist, departs, arrives), not
Flights(fno, "Madison", to, dist,departs, arrives). Note you need the
first predicate to ensure that the query is safe, similarly, you need
to name the rest of the variables to ensure that they're safe.
- Part 4: MadCity(to):-Flights(_,"Madison",to,_, _, _)
MadCity(to):-MadCity(from), Flights(_, from, to, _, _, _)
- Part 5:
MadCity(to,arrive):-Flights(_,"Madison",to,_, _, arrive)
MadCity(to, arrives):-MadCity(from,prev_arrives), Flights(_, from, to, _,
departs,arrives), prev_arrives < departs, prev_arrives + 1hr < departs
- Part 7:
MadCity(to):-Flights(_,"Madison",to,_, _, _)
MadCity(to):-MadCity(from), Flights(_, from, to, _,_, _)
Ans(fno):-Flights(fno,from,to, _, _, _), not MadCity(from), not Flights(fno,'Madison',to,_,_,_)