Created
August 1, 2012 00:27
-
-
Save xenophobia/3221978 to your computer and use it in GitHub Desktop.
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
nqueen = [egison| (lambda [$n] | |
(match-all (between 1 n) (Multiset Integer) | |
[<cons $a_1 | |
(loop $l $i (between 2 n) | |
<cons (loop $l1 $i1 (between 1 (- i 1)) | |
(& ^,(- a_i1 (- i i1)) | |
^,(+ a_i1 (- i i1)) | |
l1) | |
$a_i) | |
l> | |
<nil>)> | |
{@(loop $l $i (between 1 n) {a_i @l} {})}])) :: Int -> [[Int]]|] | |
> nqueen 5 | |
[[1,3,5,2,4],[1,4,2,5,3],[2,4,1,3,5],[2,5,3,1,4],[3,1,4,2,5],[3,5,2,4,1],[4,1,3,5,2],[4,2,5,3,1],[5,2,4,1,3],[5,3,1,4,2]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment