-- Solve the n-queens puzzle with the quantification pattern -- Sergio and Michael -- Mon Apr 18 14:23:56 PDT 2011 import Combinatorial import Quantification import SetFunctions import Integer distElem (_++[x]++_++[z]++_) = (x,z) placement n = zip [1..n] (permute [1..n]) capture (r1,c1) (r2,c2) = r1 == r2 || c1 == c2 || abs(r1-r2) == abs(c1-c2) queens n | exists r (\p -> notExists (set1 distElem p) (\(x,y) -> capture x y)) = r where r = placement n