projects
/
sandbox
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
dd2a6d0
)
Playing around with prolog
author
David Kerkeslager
<kerkeslager@gmail.com>
Tue, 13 Dec 2016 14:46:53 +0000
(09:46 -0500)
committer
David Kerkeslager
<kerkeslager@gmail.com>
Tue, 13 Dec 2016 14:46:53 +0000
(09:46 -0500)
prolog/test.pl
[new file with mode: 0644]
patch
|
blob
diff --git a/prolog/test.pl
b/prolog/test.pl
new file mode 100644
(file)
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.