From 1759f874db778ad1e9ac9c6881879f5a5f1073e0 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Tue, 13 Dec 2016 09:46:53 -0500 Subject: [PATCH] Playing around with prolog --- prolog/test.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 prolog/test.pl diff --git a/prolog/test.pl b/prolog/test.pl new file mode 100644 index 0000000..388639d --- /dev/null +++ b/prolog/test.pl @@ -0,0 +1,20 @@ +bitor(1, [1|_]). +bitor(0, [0]). +bitor(B, [0|T]) :- bitor(B, T). + +bitand(0, [0|_]). +bitand(1, [1]). +bitand(B, [1|T]) :- bitand(B, T). + +bitcomposition(0, []). +bitcomposition(N, [H|T]) :- + H is N mod 2, + Shift is N // 2, + bitcomposition(Shift, T). + + +inc(N, NPlusOne) :- add(NPlusOne, N, 1). + +add(Z, X, Y) :- var(X), X is Z - Y. +add(Z, X, Y) :- var(Y), Y is Z - X. +add(Z, X, Y) :- Z is X + Y. -- 2.20.1