diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f226b2 --- /dev/null +++ b/README.md @@ -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. \ No newline at end of file diff --git a/familytree.pl b/familytree.pl new file mode 100644 index 0000000..4577f32 --- /dev/null +++ b/familytree.pl @@ -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). \ No newline at end of file diff --git a/xor.pl b/xor.pl new file mode 100644 index 0000000..c14aaf5 --- /dev/null +++ b/xor.pl @@ -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). \ No newline at end of file