Created
October 5, 2020 00:32
-
-
Save lgastako/4ee3cb764b932046c800d0f9a75a33b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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