adding xor circuit and tutorial family tree
This commit is contained in:
parent
4a3750c723
commit
43b93918e8
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Logic Problems
|
||||||
|
|
||||||
|
Working through some logic programming problems using Prolog. Tutorial problems from post-grad AI and AI programming module with some other random problems.
|
12
familytree.pl
Normal file
12
familytree.pl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
% tree structure
|
||||||
|
parent(pam,bob).
|
||||||
|
parent(tom,bob).
|
||||||
|
parent(tom,liz).
|
||||||
|
parent(bob,ann).
|
||||||
|
parent(bob,pat).
|
||||||
|
parent(pat,jim).
|
||||||
|
|
||||||
|
predecessor(X, Z) :- parent(X, Z).
|
||||||
|
predecessor(X, Z) :- parent(X, Y), predecessor(Y, Z).
|
||||||
|
|
||||||
|
offspring(Y, X) :- parent(X, Y).
|
26
xor.pl
Normal file
26
xor.pl
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
% implement logical AND truth table
|
||||||
|
% and(IN1, IN2, OUT)
|
||||||
|
and(0,0,0).
|
||||||
|
and(0,1,0).
|
||||||
|
and(1,0,0).
|
||||||
|
and(1,1,1).
|
||||||
|
|
||||||
|
% implement logical OR truth table
|
||||||
|
% or(IN1, IN2, OUT)
|
||||||
|
or(0,0,0).
|
||||||
|
or(0,1,1).
|
||||||
|
or(1,0,1).
|
||||||
|
or(1,1,1).
|
||||||
|
|
||||||
|
% implement logical inverter
|
||||||
|
% inv(IN, OUT)
|
||||||
|
inv(0,1).
|
||||||
|
inv(1,0).
|
||||||
|
|
||||||
|
% implement XOR using rule
|
||||||
|
xor(IN1,IN2,OUT) :- inv(IN1, N1),
|
||||||
|
inv(IN2, N2),
|
||||||
|
and(IN1, N2, N3),
|
||||||
|
and(IN2, N1, N4),
|
||||||
|
or(N3, N4, OUT).
|
Loading…
Reference in New Issue
Block a user