-
Notifications
You must be signed in to change notification settings - Fork 0
/
aula4.pl
108 lines (87 loc) · 3.05 KB
/
aula4.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
:-dynamic male/1, female/1, parent/2.
:-[utils].
%1
%a
add_person:-
write('Person\'s gender: '),
read(Gender),
Gender == male,
write('Person\'s name: '),
read(Name),
\+male(Name),
assert(male(Name)).
add_person:-
write('Person\'s gender: '),
read(Gender),
Gender == female,
write('Person\'s name: '),
read(Name),
\+female(Name),
assert(female(Name)).
%b
add_parents(Person):-
write('Person\'s first parent name: '),
read(Parent1),
assert(parent(Parent1, Person)),
write('Person\'s second parent name: '),
read(Parent2),
assert(parent(Parent2, Person)).
%c
remove_person:-
write('Person\'s name: '),
read(Person),
(retract(female(Person));
retract(male(Person))).
% remove_person:-
% write('Person\'s name: '),
% read(Person),
% retract(male(Person)).
% remove_person:-
% write('Person\'s name: '),
% read(Person),
% parent(_, Person),
% retractall(parent(_, Person)).
% remove_person:-
% write('Person\'s name: '),
% read(Person),
% parent(Person, _),
% retractall(parent(Person, _)).
%2
%flight(origin, destination, company, code, hour, duration)
flight(porto, lisbon, tap, tp1949, 1615, 60).
flight(lisbon, madrid, tap, tp1018, 1805, 75).
flight(lisbon, paris, tap, tp440, 1810, 150).
flight(lisbon, london, tap, tp1366, 1955, 165).
flight(london, lisbon, tap, tp1361, 1630, 160).
flight(porto, madrid, iberia, ib3095, 1640, 80).
flight(madrid, porto, iberia, ib3094, 1545, 80).
flight(madrid, lisbon, iberia, ib3106, 1945, 80).
flight(madrid, paris, iberia, ib3444, 1640, 125).
flight(madrid, london, iberia, ib3166, 1550, 145).
flight(london, madrid, iberia, ib3163, 1030, 140).
flight(porto, frankfurt, lufthansa, lh1177, 1230, 165).
%a
% matildes's answer
get_all_nodes(ListOfAirports):-
setof(Origin, (Destination, Company, Code, Hour, Duration)^flight(Origin, Destination, Company, Code, Hour, Duration), L1),
setof(Destination, (Origin, Company, Code, Hour, Duration)^flight(Origin, Destination, Company, Code, Hour, Duration), L2),
append(L1, L2, L3),
sort(L3, ListOfAirports).
%b
most_diversified_count([], _Company, 0).
most_diversified_count([CompanyListHead | CompanyListTail], Company, Count):-
most_diversified_count(CompanyListTail, Company, Count),
setof(_Destination, (_Origin, CompanyListHead, _Code, _Hour, _Duration)^
flight(_Origin, _Destination, CompanyListHead, _Code, _Hour, _Duration), DestinationList),
array_size(DestinationList, NewCount2),
Count > NewCount2,
!.
most_diversified_count([Company | _CompanyListTail], Company, Count):-
setof(_Destination, (_Origin, Company, _Code, _Hour, _Duration)^
flight(_Origin, _Destination, Company, _Code, _Hour, _Duration), DestinationList),
array_size(DestinationList, Count),
!.
most_diversified(Company):-
setof(_Company, (_Origin, _Destination, _Code, _Hour, _Duration)^
flight(_Origin, _Destination, _Company, _Code, _Hour, _Duration), CompanyList),
most_diversified_count(CompanyList, Company, _Count).