Skip to content

Instantly share code, notes, and snippets.

@xenophobia
Created August 1, 2012 00:27
Show Gist options
  • Save xenophobia/3221978 to your computer and use it in GitHub Desktop.
Save xenophobia/3221978 to your computer and use it in GitHub Desktop.
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