% Rename this file as "chooseN.pl" and use SWI-Prolog to run it % this program aims at finding the # choices that are possible i.e N C K (N choose K) % cantake(dept, course) denotes that the student of this dept can take this course cantake(cs, no1). cantake(cs, no2). cantake(cs, no3). cantake(cs, no4). cantake(cs, no5). cantake(cs, no6). cantake(cs, no7). cantake(cs, no8). cantake(cs, no9). cantake(cs, no10). cantake(cs, no11). cantake(cs, no12). %assign(cs,6,0,[],L,[]). gives L = [no6, no5, no4, no3, no2, no1] assign(Dept,N,N,L,L,_). assign(Dept,N,A,L,R,Taken):- cantake(Dept,Course), \+member(Course, Taken), \+member(Course, L), append([Course], L, L1), A1 is A+1, assign(Dept, N, A1, L1, R,Taken). %chooseN(Dept, N, L, Taken) where N is the # courses that we are trying to select and L is the List that will contain the list of the courses (of length N) that the student can take and Taken is the list of courses that the student has already taken chooseN(Dept, N, L, Taken):- assign(Dept,N,0,[],L,Taken). % R will store a list of lists which will contain all the possible combinations in which the "N" courses can be taken %my_setof(Dept,N,R):- setof(L,chooseN(Dept,N,L),R).