module Main where

import Data.List(intersperse)

---- data ----

type Queen = (Int,Int)
type Board = [Queen]

---- display ----

dispBoard = (sep++) . (++sep) . unlines . map dispQ
  where dispQ (_,k) = ('|':) . (++"|") . intersperse ' '
                      $ r k ++ 'Q' : r (7-k)
          where r = flip take $ repeat '·'
        sep = "+---------------+\n"

        
---- logic ----

-- attacks :: Queen -> Queen -> Bool
attacks (ax,ay) (bx,by) = ax == bx
                       || ay == by
                       || abs (ax - bx) == abs (ay - by)

none :: Foldable t =>-> Bool) -> t α -> Bool
none = (not.) . any

-- legal :: Queen -> Board -> Bool
legal q = none . attacks $ q

-- solve :: [Board]
solve = s []
  where s board | line == 8 = [board]
                | otherwise = concatMap s possibles
          where line = length board
                possibles = [((line,y):board) | y <- [0..7], legal (line,y) board]
                
---- main ----
main = putStrLn $
  (++"\n"++show (length solutions)++" solutions.")
  . unlines . map dispBoard $ solutions
  where solutions = solve

Generated by Mikaƫl Dusenne using scpaste at Sat Aug 5 14:46:16 2017. CEST. (original)