You are on page 1of 2

%member(E,L)shouldbetrueif

%EisatoplevelmemberofthelistL
%membershouldworkwhenEisavariableorbound
toavalue;
%Lshouldonlybeboundtoavalue
%
member(E,[E|_]).
member(E,[_|R]):member(E,R).

getVar([_,L,_],N):getVar(L,N).
getVar([_,L,R],N):noVars(L),
getVar(R,N).

%range(L,H,List)shouldbetrueif
%ListisalistofintegersfromLtoH1,
%inclusive.BothLandHneedtobeboundtoints
asinputs.
%Thethirdinput,List,willthenbegenerated.
%
range(L,H,[]):L>=H.
range(L,H,[L|R]):L<H,MisL+1,range(M,H,R).

eval(t,t).
eval(f,f).
eval([not,L],t):eval(L,f).
eval([not,L],f):eval(L,t).
eval([or,L,R],t):eval(L,t);eval(R,t).
eval([or,L,R],f):eval(L,f),eval(R,f).
eval([and,L,R],t):eval(L,t),eval(R,t).
eval([and,L,R],f):eval(L,f);eval(R,f).
eval([ifthen,L,R],t):eval(L,f);eval(R,t).
eval([iff,L,R],t):L==R.

%%[Part1]rev(L,Rev)
rev([],[]).
rev([H|T],R):rev(T,RevT),append(RevT,[H],R).
%%[Part2]count(E,L,N)
count(E,[],N).
count(E,[F|R],N):F\=E,count(E,R,N).
count(E,[E|R],N):A=N+1,count(E,R,A).
%%[Part3]find(Pattern,Target,Index)
find([P],[P|Y],0).
find([A|B],[A|Y],0):B\==[],find(B,Y,0).
find([A|B],[X|Y],I):B\==[],find([A|B],Y,
H),IisH+1.
%%[Part4]depth(E,Tree,N)
depth(E,[E,_,_],0).
depth(E,[A,X,_],N):depth(E,X,Y),NisY+1,E
<A.
depth(E,[A,_,X],N):depth(E,X,Y),NisY+1,A
<E.
%%[Part5]insert(E,Tree,NewTree)
insert(E,[],[E,[],[]]).
insert(E,[E,_,_],[E,_,_]).
insert(E,[Node,Left,Right],[Node,NewLeft,
Right]):insert(E,Left,NewLeft),E<Node.
insert(E,[Node,Left,Right],[Node,Left,
NewRight]):insert(E,Right,NewRight),E>Node.
%%[Part6]path(A,B,Graph,Path)
path(X,X,_,[X]).
path(X,Y,[[Src,Dst]|Rest],Path):path(X,Src,
Rest,Newpath1),path(Dst,Y,Rest,Newpath2),
append(Newpath1,Newpath2,Path);path(X,Y,Rest,
Path).
noVars(t).
noVars(f).
noVars([_,L,R]):noVars(L),noVars(R).
noVars([_,S]):noVars(S).
getVar(N,N):number(N).
getVar([_,Sub],N):getVar(Sub,N).
getVar([_,L,_],N):getVar(L,N).
getVar([_,L,R],N):noVars(L),
getVar(R,N).
getVar(N,N):number(N).
getVar([_,Sub],N):getVar(Sub,N).

%eval

logic(Seats):
Seats=[[bruno,_,_],_,[_,hmc,spam],_,[dino,
_,_]],
nextTo([algird,_,_],[_,hmc,_],Seats),
nextTo([collette,_,_],[_,_,chocolate],Seats),
nextTo([collette,_,_],[_,_,donuts],Seats),
lr([_,_,chocolate],[_,_,pez],Seats),
nextTo([_,pomona,_],[_,_,jots],Seats),
nextTo([_,pomona,_],[_,_,spam],Seats),
seats(Seats),
\+nextTo([dino,_,_],[_,_,donuts],Seats),
\+nextTo([edwina,_,_],[_,cmc,_],Seats),
\+member([bruno,scripps,_],Seats),
\+member([dino,scripps,_],Seats),
\+member([algird,scripps,_],Seats).
%%XisachildofYifYisaparentofX
%
child(X,Y):parent(Y,X).
%%ifXisfemaleandXisaparentofY
%
mother(X,Y):female(X),parent(X,Y).
anc(X,Y):parent(X,Y).
anc(X,Y):parent(Z,Y),anc(X,Z).
%run_tests(grandparent)
:begin_tests(grandparent).
test(grandparentT1,[nondet]):grandparent(jackie,
bart).
test(grandparentT2,[nondet]):grandparent(john,
bart).
test(grandparentT3,[nondet]):grandparent(helga,
homer).
test(grandparentT4):
setof(OneGP,grandparent(OneGP,bart),
AllGPs),
AllGPs==[homericus,jackie,john,matilda].
test(grandparentT5):\+grandparent(marge,homer).
%addadditionaltestsbelow:
test(grandparentT5):\+grandparent(homer,homer).
:end_tests(grandparent).
:dynamicthing_at/2,player_at/1,studied/1,
office_hours/1,ae/1,inv/1.
player_at(jacobs).
retract(thing_at(X,Place)),
assert(thing_at(X,in_hand)),
invAddOne:inv(N),
NewNisN+1,

retract(inv(N)),
assert(inv(NewN)).

You might also like