From: David Kerkeslager Date: Tue, 13 Dec 2016 14:46:53 +0000 (-0500) Subject: Playing around with prolog X-Git-Url: https://code.kerkeslager.com/?p=sandbox;a=commitdiff_plain;h=1759f874db778ad1e9ac9c6881879f5a5f1073e0 Playing around with prolog --- 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.