Created
February 21, 2019 20:39
-
-
Save kubaracek/e170229c70b7558571fa18f5fa047622 to your computer and use it in GitHub Desktop.
This file contains 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
module Sudoku where | |
import Data.List (length, nub) | |
import Data.Matrix (Matrix, fromLists, safeSet, getRow, getCol) | |
import Data.Vector (Vector, filter, uniq) | |
type Board = Matrix (Maybe Int) | |
type Coord = (Int, Int) | |
validateVector :: Vector (Maybe Int) -> Bool | |
validateVector xs = | |
length (uniq (xsNoNothing)) == length xsNoNothing | |
where | |
xsNoNothing = Data.Vector.filter (/= Nothing) xs | |
setCoord :: Board -> Coord -> Int -> Maybe Board | |
setCoord board (x,y) val = | |
safeSet (Just val) (x,y) board | |
checkCoord :: Board -> Coord -> Bool | |
checkCoord board (x,y) = | |
all (==True) [ | |
validateVector $ getRow x board | |
, validateVector $ getCol y board | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment