Created
November 25, 2019 22:25
-
-
Save ignaciomosca/1743a4c3e340ceb41df1278d2b619f60 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
findCandidate :: ChessPiece -> Board -> Set Board | |
findCandidate p b | |
= Data.Set.fromList $ | |
[ newBoard | |
| rr <- [1 .. (m b)] | |
, cc <- [1 .. (n b)] | |
, let pp = createPiece (piece p) rr cc | |
, let newBoard = place b pp | |
, isSafe b pp] | |
solution :: Board -> [ChessPiece] -> Set Board -> Set Board | |
solution board (p : ps) solutions = solution board ps (Data.Set.Extra.flatten (Data.Set.map (findCandidate p) solutions)) | |
solution board [] solutions = Data.Set.filter done solutions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment