Skip to content

Instantly share code, notes, and snippets.

@kubaracek
Created February 21, 2019 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubaracek/e170229c70b7558571fa18f5fa047622 to your computer and use it in GitHub Desktop.
Save kubaracek/e170229c70b7558571fa18f5fa047622 to your computer and use it in GitHub Desktop.
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