Skip to content

Lab 5 #4

@BertLisser

Description

@BertLisser

Exercise 2. Good but refactoring can be more complete.
In many more places it is possible to replace Constraints by [Position]

type Node = (Sudoku,[Position])
prune :: (Row,Column,Value)
      -> [Position] -> [Position]
constraints :: Sudoku -> [Position]

Why not using

eraseN :: Node -> (Row,Column) -> Node
eraseN n (r,c) = (s, constraints s)

and

Ex. 3

minimal :: Grid -> Bool
minimal g = solutionCount g == 1
            && all (\x -> solutionCount x > 1) (smallerProblems g)

Why not using

eraseN :: Node -> (Row,Column) -> Node
eraseN n (r,c) = (s, constraints s)

and

uniqueSol :: Node -> Bool
uniqueSol node = singleton (solveNs [node]) where
  singleton [] = False
  singleton [x] = True
  singleton (x:y:zs) = False

Exercise 4

doExercise4 :: IO()
doExercise4 = do [r] <- rsolveNs [emptyN]
                 showNode r
                 s <- genProblemEmptyBlocks 20 r
                 print$uniqueSol s  // There are cases that s doesn't have an unique solution
                 showNode s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions