Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
9,869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1.  
  2. %-----------------DATABASE-----------------%
  3.  
  4. %airport(Name,ICAO,Country)-.
  5. airport('Aeroport Francisco Sa Carneiro','LPPR','Portugal').
  6. airport('Aeroporto Humberto Delgado','LPPT','Portugal').
  7. airport('Aeropuerto Adolfo Suarez Madrid-Barajas', 'LMED','Spain').
  8. airport('Aeroport de Paris-Charles-de-Gaulle Roissy Airport','LFPG','France').
  9. airport('Aeroporto Internazionale di Roma-Fiumicino - Leonardo da Vinci', 'LIRF','Italy').
  10.  
  11. %company(ICAO, Name, Year, Country).
  12. company('TAP', 'TAP Air Portugal',1945, 'Portugal').
  13. company('RYR','Ryanair',1984,'Ireland').
  14. company('AFR','Societe Air France, S.A',1933,'France').
  15. company('BAW','British Airways', 1974, 'United Kingdom').
  16.  
  17. %flight(Designation, Origin, Destination, DepatureTime, Duration, Company).
  18. flight('TP1923','LPPR','LPPT',1115,55,'TAP').
  19. flight('TP1968','LPPT','LPPR',2235,55,'TAP').
  20. flight('TP842','LPPT','LIRF',1450,195,'TAP').
  21. flight('TP843','LIRF','LPPT',1935,195,'TAP').
  22. flight('FR5483','LPPR','LEMD',630,105,'RYR').
  23. flight('FR5484','LEMD','LPPR',1935,105,'RYR').
  24. flight('AF1024','LPPG','LPPT',940,155,'AFR').
  25. flight('AF1025','LPPT','LFPG',1310,155,'AFR').
  26. %-----------------EXERCISES-----------------%
  27. short(Flight):-
  28. flight(Flight,_,_,_,Duration,_),
  29. Duration < 90.
  30.  
  31. % . . . . . . . . . . . . . . . . . . . . . . %
  32.  
  33. shorter(Flight1,Flight2,ShorterFlight):-
  34. flight(Flight1,_,_,_,Duration1,_),
  35. flight(Flight2,_,_,_,Duration2,_),
  36. Duration1 < Duration2,
  37. ShorterFlight = Flight1.
  38. shorter(Flight1,Flight2,ShorterFlight):-
  39. flight(Flight1,_,_,_,Duration1,_),
  40. flight(Flight2,_,_,_,Duration2,_),
  41. Duration1 > Duration2,
  42. ShorterFlight = Flight2.
  43. shorter(Flight1,Flight2,ShorterFlight):-
  44. fail.
  45.  
  46. % . . . . . . . . . . . . . . . . . . . . . . %
  47.  
  48. arrivalTime(Flight,ArrivalTime):-
  49. flight(Flight,_,_,DepartureTime,Duration,_),
  50. DepMinutes is DepartureTime mod 100,
  51. TotMinutes is DepMinutes + Duration,
  52. Minutes is TotMinutes mod 60,
  53. Hours = TotMinutes // 60,
  54. ArrivalTime is DepartureTime +100 * Hours - DepMinutes + Minutes.
  55.  
  56. % . . . . . . . . . . . . . . . . . . . . . . %
  57.  
  58. countries(Company,ListOfCountries):-
  59. append([],[],ListOfCountries),
  60. make_list(ListOfCountries).
  61.  
  62. make_list(ListOfCountries):-
  63. airport(_,_,Country),
  64. operates_in_country(Company,Country),
  65. append(ListOfCountries,[],OldListOfCountries),
  66. write(OldListOfCountries),nl,
  67. append(OldListOfCountries,[Country],NewListOfCountries),
  68. write(NewListOfCountries),nl,
  69. fail.
  70.  
  71. operates_in_country(Company,Country):-
  72. flight(_,Origin,_,_,_,Company),
  73. airport(_,Origin,Country),
  74. !.
  75. operates_in_country(Company,Country):-
  76. flight(_,_,Destination,_,_,Company),
  77. airport(_,Destination,Country).
  78.  
  79. % . . . . . . . . . . . . . . . . . . . . . . %
  80.  
  81. pairableFlights:-
  82. \+ print.
  83.  
  84. print:-
  85. flight(Designation1, _, Destination,_, _, _),
  86. flight(Designation2, Destination,_, D2,_, _),
  87. arrivalTime(Designation1,ArrivalTime),
  88. DiffTime is ArrivalTime - D2,
  89. write(DiffTime),nl,
  90. DiffTime >= 30,
  91. DiffTime =< 90,
  92. write(Destination), write(' - '),write(Designation1), write(' / '), write(Designation2),nl,
  93. fail.
  94.  
  95.  
  96.  
  97. % . . . . . . . . . . . . . . . . . . . . . . %
  98.  
  99. tripDays(Trip,Time,FlightDays,Days):-
  100.  
  101.  
  102.  
  103. % . . . . . . . . . . . . . . . . . . . . . . %
  104.  
  105. %-----------------TEST SECTION-----------------%
  106. test:-
  107. pairableFlights.
  108.  
  109.  
  110.  
  111. %-----------------------------------------------%
  112.  
  113. % compile('/Users/gustavonrm/Desktop/test/test2018.pl').
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement