Created
September 12, 2013 13:22
-
-
Save thezerobit/6537188 to your computer and use it in GitHub Desktop.
knights moves in Prolog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% example: move([0,0],[X,Y],7,7). | |
% because this is not right: https://github.com/clojure/core.logic/wiki/Translations-from-prolog | |
move([X, Y], [A, B], Xmax, Ymax) :- | |
member([Dx,Dy],[[1,2],[2,1],[2,-1],[1,-2],[-1,-2],[-2,-1],[-2,1],[-1,2]]), | |
A is X + Dx, | |
B is Y + Dy, | |
between(0, Xmax, A), | |
between(0, Ymax, B). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And an experienced core.logic user might write it this way:
We try our best - it's true that Prolog programs often turn out a little bit shorter.