Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- domains
- faculty_name, second_name, name, subject = symbol
- spec_code, group_number, mark, military_department = real
- group=group(faculty_name, spec_code, group_number, list_composition)
- list_composition=composition*
- composition=composition(second_name, name, military_department, list_vedomost)
- list_vedomost=vedomost*
- vedomost=vedomost(subject, mark)
- facts
- average_mark(real,real)
- min_students(group_number, real)
- dq3(group_number,subject)
- dq4(group_number, spec_code)
- dq5(faculty_name, group_number)
- predicates
- nondeterm groups(group)
- q1(group_number)
- q11(real, list_composition, real, real, real)
- q12(real,list_vedomost,real,real,real)
- q2
- q21(list_composition, real)
- nondeterm q3(real)
- nondeterm q31(real,list_composition)
- nondeterm q32(real,list_vedomost)
- q4(group_number)
- q5(faculty_name)
- clauses
- groups(group("faculty name1",6,6102,[composition("Mike","Gordon",1, [vedomost("Phys", 5), vedomost("Math", 3), vedomost("Lang", 4)]),
- composition("Sam", "Jackson", 0, [vedomost("SII", 3), vedomost("Religion", 2)])])).
- groups(group("faculty name1",2,6208,[composition("Sally","Smith",0, [vedomost("Eloctronic", 4), vedomost("Mech", 5)]),
- composition("Jack", "Lowson", 0, [vedomost("Program", 2), vedomost("Math", 3), vedomost("Eng", 5)])])).
- groups(group("faculty name2",4,6311,[composition("Andy","White",1, [vedomost("History", 5)])])).
- average_mark(0,0).
- q1(N):-
- groups(group(_,_,N,L)),
- q11(N,L,0,C,0),
- average_mark(E,R),
- C>R,
- retract(average_mark(E,R)),
- assert(average_mark(N,C)),fail.
- q11(_,[],Z1,Z,G):-Z=Z1/G.
- q11(A1,[H|T],Y,W,Q):-H=composition(_,_,_,U),q12(A1,U,0,V,0),Y1=Y+V, Q1=Q+1, q11(A1,T,Y1,W,Q1).
- q12(_,[],D1,D,P):-D=D1/P.
- q12(F,[H1|T1],D1,D2,P1):-H1= vedomost(_,Z), D3=D1+Z, P3=P1+1,
- q12(F,T1,D3,D2,P3).
- min_students(6102,23321456).
- q2:-
- groups(group(_,_,GN,L)),
- min_students(Q,M),
- q21(L,N),
- N<M,
- retract(min_students(Q,M)),
- assert(min_students(GN,N)), fail.
- q21([_|T],N):-q21(T,N1),N=N1+1.
- q21([],0).
- %q3(K):-groups(group(_,_,K,L)), q31(L).
- %q31([]).
- %q31([H|T]):-H=composition(_,_,_,V),q32(V),q31(T).
- %q32([]).
- %q32([H1|T1]):-H1=vedomost(S,_), write(S),nl, q32(T1).
- q3(GN):- dq3(GN,S),write('#',S), nl,fail.
- q3(GN):- not(dq3(GN,_)),groups(group(_,_,GN,L)), q31(GN,L), fail.
- q31(GN,[H|T]):-H=composition(_,_,_,L1), q32(GN,L1), q31(GN,T).
- q31(_,[]).
- q32(GN,[H1|T1]):-H1=vedomost(S,_), assert(dq3(GN,S)), write(S), nl,q32(GN,T1).
- q32(_,[]).
- q4(G):-groups(group(_,C,G,_)), write(C), nl, fail.%ñòàòè÷åñêèé
- q4(G):-dq4(G,A), write(G," ",A), nl, fail.%äèíàìè÷åñêèé
- q4(G):- not(dq4(G,_)), groups(group(_,C,G,_)), write(C), nl, assert(dq4(G,C)), fail.
- q5(K):-groups(group(K,_,A,_)), write(A), nl, fail.%ñòàòè÷åñêèé
- q5(K):-dq5(K,N), write(K," ",N), nl, fail.%äèíàìè÷åñêèé
- q5(K):-not(dq5(K,_)), groups(group(K,_,N,_)), write(N), nl, assert(dq5(K,N)), fail.
- goal
- %q1(6311); average_mark(N,C).
- %q2; min_students(A,B).
- %q3(6208).
- q3(6208);q3(6208).
- %q4(6311); q4(6311).
- %write("Code:"), nl,q4(6311).
- %write("Groups:"),nl,q5("faculty name1").
- %q5("faculty name1");q5("faculty name1").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement