Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 5 #3

Open
BertLisser opened this issue Oct 12, 2018 · 2 comments
Open

Lab 5 #3

BertLisser opened this issue Oct 12, 2018 · 2 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 12, 2018

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]

Exercise 3

minimalSudoku :: Node -> Bool
minimalSudoku node = not $ any uniqueSol (parents node)

must become

minimalSudoku :: Node -> Bool
minimalSudoku node = (not $ any uniqueSol (parents node)) &&  (uniqueSol node)

Exercise 4

checkEmptyBlockSudoku :: Int -> IO ()
checkEmptyBlockSudoku n = do [r] <- rsolveNs [emptyN]
                             showNode r
                             xs <- shuffleBlocks
                             -- xs <- blocksToEmpty n
                             let xs' = take n xs
                             let r' = cleanBlocks r xs'
                             if uniqueSol r' then do
                                s  <- genProblem r'
                                showNode s
                             else checkEmptyBlockSudoku n

better

checkEmptyBlockSudoku :: Int -> IO ()
checkEmptyBlockSudoku n = do [r] <- rsolveNs [emptyN]
                             showNode r
                             xs <- shuffleBlocks
                             -- xs <- blocksToEmpty n
                             let xs' = take n xs
                             let r' = cleanBlocks r xs'
                             s  <- genProblem r'
                             if uniqueSol s then do             
                                showNode s
                             else checkEmptyBlockSudoku n

In the old way you will miss possible unique solutions.

@njtromp
Copy link
Contributor

njtromp commented Oct 16, 2018

Could you please elaborate on how you envision the refactoring of Constraint?
Given our types

type Position = (Row,Column)
type Constrnt = [[Position]] -- Mind the missing 'ai' in the spelling as this is copied from the assignment

the refactoring of type Constraint = (Row,Column,[Value]) would lead to type Constraint = (Position,[Value]) which would lead to

type Node = (Sudoku,[(Position,[Value])])

which is different then the suggested refactoring in the issue!

type Node = (Sudoku,[Position])

The list of values is missing in this case.

@BertLisser
Copy link
Author

You don't need this because you can always call freeAtPos for getting [Value]. But I admitted this is expensive. But missed a remark like that it is ugly to have to similar types Constraint and Constrnt. It looks as if the refactoring task is not finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants