From 3f11463f5535acae588cb4acecbf73e9e1fa7369 Mon Sep 17 00:00:00 2001 From: dipsywong98 Date: Mon, 27 Nov 2017 18:50:04 +0800 Subject: [PATCH] fix task3 order problem --- assignment3/ass3.pl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/assignment3/ass3.pl b/assignment3/ass3.pl index 83c2832..d52b8cb 100644 --- a/assignment3/ass3.pl +++ b/assignment3/ass3.pl @@ -37,13 +37,23 @@ common_enroll(SA,SB,L):-enroll(SA,CA),enroll(SB,CB),SA\=SB,helperq2(CA,CB,L). common_enroll(_,_,_):-fail. +rev_helper([X|L],R,LL):-rev_helper(L,[X|R],LL). +rev_helper([],L,L). +rev(L,R):-var(R),rev_helper(L,[],R),!. +rev(L,R):-var(L),rev_helper(R,[],L),!. +rev(L,R):-rev_helper(L,[],R). + union([],L, L). union([X | X1], Y, L) :- member(X,Y), union(X1, Y, L),!. union([X | X1], Y, [X | L]) :- union(X1, Y, L). -all_students_helper(F,[S|SL]):-enroll(S,_),\+member(S,F),all_students_helper([S|F],SL),!. -all_students_helper(_,[]). -all_students(SL):-all_students_helper([],SL). +% all_students_helper(F,[S|SL]):-enroll(S,_),\+member(S,F),all_students_helper([S|F],SL),!. +% all_students_helper(_,[]). +% all_students(SL):-all_students_helper([],SL). + +all_students_helper(F,[S|SL],K):-enroll(S,_),\+member(S,F),all_students_helper([S|F],SL,K),!. +all_students_helper(K,[],K). +all_students(K):-all_students_helper([],_,K). intersect([X|_],Y):-member(X,Y),!. intersect([_|XL],Y):-intersect(XL,Y). @@ -80,4 +90,4 @@ enroll_list(C,SL):-var(C),course_list(CL),member(C,CL),all_students(ALL_S),enroll_list_helper(C,ALL_S,SL). enroll_list(C,SL):- \+ var(C), all_students(ALL_S),enroll_list_helper(C,ALL_S,SL),!. -count_students(C,N):-enroll_list(C,L),get_length(L,N). \ No newline at end of file +count_students(C,N):-enroll_list(C,L),get_length(L,N).