Skip to content

Instantly share code, notes, and snippets.

@lgastako
Created October 5, 2020 00:32
Show Gist options
  • Save lgastako/4ee3cb764b932046c800d0f9a75a33b4 to your computer and use it in GitHub Desktop.
Save lgastako/4ee3cb764b932046c800d0f9a75a33b4 to your computer and use it in GitHub Desktop.
import qualified Data.Set as Set
type Row = Int
type Col = Int
renderSols :: [[(Row, Col)]] -> IO ()
renderSols = mapM_ (putStrLn . renderQs . Set.fromList)
where
renderQs queens = unlines $ map renderRow (range maxRow)
where
renderRow r = map renderCol (range maxCol)
where
renderCol c
| (r, c) `Set.member` queens = 'Q'
| otherwise = '-'
maxRow = 5
maxCol = 5
range n = [0..n-1]
solutions :: [[(Row, Col)]]
solutions = replicate 3 [(0, 3), (1, 1), (2, 4), (3, 2), (4, 0)]
main :: IO ()
main = renderSols solutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment