Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
12
Task/N-queens-problem/Haskell/n-queens-problem-3.hs
Normal file
12
Task/N-queens-problem/Haskell/n-queens-problem-3.hs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import Data.List (nub, permutations)
|
||||
|
||||
-- checks if queens are on the same diagonal
|
||||
-- with [0..] we place each queen on her own row
|
||||
check f = length . nub . zipWith f [0..]
|
||||
|
||||
-- filters out results where 2 or more queens are on the same diagonal
|
||||
-- with [0..n-1] we place each queeen on her own column
|
||||
generate n = filter (\x -> check (+) x == n && check (-) x == n) $ permutations [0..n-1]
|
||||
|
||||
-- 8 is for "8 queens"
|
||||
main = print $ generate 8
|
||||
Loading…
Add table
Add a link
Reference in a new issue