Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
NQueens
--ghc 7.10 {-# LANGUAGE TupleSections #-} type Queen = (Int, Int) --x,y type BoardConfig = [Queen] isThreatens :: Queen -> Queen -> Bool isThreatens (x1, y1) (x2, y2) = (x1 == x2) || (y1 == y2) || abs (x2 - x1) == abs (y2 - y1) canAddQ :: [Queen] -> Queen -> Bool canAddQ qs q = all (==False) $ map (isThreatens q) qs cols :: Int -> [Queen] cols y = map (,y) [1..8] buildQs :: BoardConfig -> [BoardConfig] buildQs config = if length config == 8 then [config] else concat $ filter (not . null) (map buildQs potentialConfigs) where potentialQs = filter (canAddQ config) (cols (length config + 1)) potentialConfigs = map (:config) potentialQs main = print $ buildQs [] -- [config, config, config] -> [config, config, config, config, config, config
run
|
edit
|
history
|
help
0
prettier Tasty
Derive type class for parameterized data type
Kleiner dan tien
(-‿‿-)
Lowest Common Ancestor in a Binary Tree
Perfect numbers
project euler 6, haskell
Reader
project euler 3, haskell
mySqrt