Smap
SmapIE
New program
Curry
Prolog
Haskell
Open program by ID
Browser
Dashboard
Programs on Smap
Most recent
Most favorited
Tags on Smap
All tags
Sign in
Help
Source code
Language:
Curry
-- Solving the n-queens problem in Curry with FD constraints -- This example requires the library CLPFD with is available in PAKCS: import CLPFD -- specification of the n-queens problem with FD constraints: queens n xs = genVars n =:= xs & domain xs 1 (length xs) & allSafe xs & labeling [FirstFail] xs -- a placement is safe if each queen cannot attack another queen allSafe [] = success allSafe (q:qs) = safe q qs 1 & allSafe qs safe :: Int -> [Int] -> Int -> Success safe _ [] _ = success safe q (q1:qs) p = noAttack q q1 p & safe q qs (p+#1) noAttack q1 q2 p = q1 /=# q2 & q1 /=# q2+#p & q1 /=# q2-p -- return a list of fresh variables genVars n = if n==0 then [] else _ : genVars (n-1) -- Solving the classical 8-queens problem: main = queens 8 xs &> xs where xs free
Execution result
No execution result yet.
PAKCS 3.7 /all-values
PAKCS 3.7 /one-value
KiCS2 3.1 /all-values
KiCS2 3.1 /one-value
Reset
Clear
Options
New Curry program
Reload program 7
View in Browser
Program ID:
7
Title:
Queens with FD constraints
Language:
Curry
Author:
mh
Version:
2
Program information