Skip to content

Commit

Permalink
fix task3 order problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dipsywong98 committed Nov 27, 2017
1 parent a393588 commit 3f11463
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions assignment3/ass3.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
count_students(C,N):-enroll_list(C,L),get_length(L,N).

0 comments on commit 3f11463

Please sign in to comment.