Commit 65107cf632cd3881fc1687dbc85fa2ff03e24275 Parent: 7697d0092a5a1a4a3c80ae35c2d201767b50bbc8 Author: mcol <mcol@posteo.net> Date: 2022-04-03 17:35:03 +0100 Committer: mcol <mcol@posteo.net> Committed: 2022-04-03 17:35:03 +0100 hlint
sudoku.hs Modified
@@ -1,5 +1,7 @@ #!/usr/bin/env runhaskell +{-# LANGUAGE TupleSections #-} + {- sudoku-solver script. Copyright Matt Colligan 2022. -} @@ -41,15 +43,15 @@ isValid p = all (goodSet p) blocks where goodSet :: Puzzle -> [Index] -> Bool - goodSet p = noRepeats . catMaybes . map ((!) p) + goodSet p = noRepeats . mapMaybe (p !) noRepeats cs = length cs == length (nub cs) blocks :: [[Index]] blocks = concat [rows, cols, boxes] - rows = map (\r -> map ((,) r) set) set - cols = map (\c -> map (flip (,) c) set) set - boxes = map makeBox [(r, c) | r <- [One, Four, Seven], c <- [One, Four, Seven]] + rows = map (\r -> map (r,) set) set + cols = map (\c -> map (,c) set) set + boxes = [makeBox (r, c) | r <- [One, Four, Seven], c <- [One, Four, Seven]] makeBox :: Index -> [Index] makeBox (r, c) = [(r, c) | r <- [r .. succ . succ $ r], c <- [c .. succ . succ $ c]]