Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %-----------------DATABASE-----------------%
- %airport(Name,ICAO,Country)-.
- airport('Aeroport Francisco Sa Carneiro','LPPR','Portugal').
- airport('Aeroporto Humberto Delgado','LPPT','Portugal').
- airport('Aeropuerto Adolfo Suarez Madrid-Barajas', 'LMED','Spain').
- airport('Aeroport de Paris-Charles-de-Gaulle Roissy Airport','LFPG','France').
- airport('Aeroporto Internazionale di Roma-Fiumicino - Leonardo da Vinci', 'LIRF','Italy').
- %company(ICAO, Name, Year, Country).
- company('TAP', 'TAP Air Portugal',1945, 'Portugal').
- company('RYR','Ryanair',1984,'Ireland').
- company('AFR','Societe Air France, S.A',1933,'France').
- company('BAW','British Airways', 1974, 'United Kingdom').
- %flight(Designation, Origin, Destination, DepatureTime, Duration, Company).
- flight('TP1923','LPPR','LPPT',1115,55,'TAP').
- flight('TP1968','LPPT','LPPR',2235,55,'TAP').
- flight('TP842','LPPT','LIRF',1450,195,'TAP').
- flight('TP843','LIRF','LPPT',1935,195,'TAP').
- flight('FR5483','LPPR','LEMD',630,105,'RYR').
- flight('FR5484','LEMD','LPPR',1935,105,'RYR').
- flight('AF1024','LPPG','LPPT',940,155,'AFR').
- flight('AF1025','LPPT','LFPG',1310,155,'AFR').
- %-----------------EXERCISES-----------------%
- short(Flight):-
- flight(Flight,_,_,_,Duration,_),
- Duration < 90.
- % . . . . . . . . . . . . . . . . . . . . . . %
- shorter(Flight1,Flight2,ShorterFlight):-
- flight(Flight1,_,_,_,Duration1,_),
- flight(Flight2,_,_,_,Duration2,_),
- Duration1 < Duration2,
- ShorterFlight = Flight1.
- shorter(Flight1,Flight2,ShorterFlight):-
- flight(Flight1,_,_,_,Duration1,_),
- flight(Flight2,_,_,_,Duration2,_),
- Duration1 > Duration2,
- ShorterFlight = Flight2.
- shorter(Flight1,Flight2,ShorterFlight):-
- fail.
- % . . . . . . . . . . . . . . . . . . . . . . %
- arrivalTime(Flight,ArrivalTime):-
- flight(Flight,_,_,DepartureTime,Duration,_),
- DepMinutes is DepartureTime mod 100,
- TotMinutes is DepMinutes + Duration,
- Minutes is TotMinutes mod 60,
- Hours = TotMinutes // 60,
- ArrivalTime is DepartureTime +100 * Hours - DepMinutes + Minutes.
- % . . . . . . . . . . . . . . . . . . . . . . %
- countries(Company,ListOfCountries):-
- append([],[],ListOfCountries),
- make_list(ListOfCountries).
- make_list(ListOfCountries):-
- airport(_,_,Country),
- operates_in_country(Company,Country),
- append(ListOfCountries,[],OldListOfCountries),
- write(OldListOfCountries),nl,
- append(OldListOfCountries,[Country],NewListOfCountries),
- write(NewListOfCountries),nl,
- fail.
- operates_in_country(Company,Country):-
- flight(_,Origin,_,_,_,Company),
- airport(_,Origin,Country),
- !.
- operates_in_country(Company,Country):-
- flight(_,_,Destination,_,_,Company),
- airport(_,Destination,Country).
- % . . . . . . . . . . . . . . . . . . . . . . %
- pairableFlights:-
- \+ print.
- print:-
- flight(Designation1, _, Destination,_, _, _),
- flight(Designation2, Destination,_, D2,_, _),
- arrivalTime(Designation1,ArrivalTime),
- DiffTime is ArrivalTime - D2,
- write(DiffTime),nl,
- DiffTime >= 30,
- DiffTime =< 90,
- write(Destination), write(' - '),write(Designation1), write(' / '), write(Designation2),nl,
- fail.
- % . . . . . . . . . . . . . . . . . . . . . . %
- tripDays(Trip,Time,FlightDays,Days):-
- % . . . . . . . . . . . . . . . . . . . . . . %
- %-----------------TEST SECTION-----------------%
- test:-
- pairableFlights.
- %-----------------------------------------------%
- % compile('/Users/gustavonrm/Desktop/test/test2018.pl').
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement