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 #4

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

Lab 5 #4

BertLisser opened this issue Oct 12, 2018 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 12, 2018

Ex  2
The following is Okay

constraints :: Sudoku -> [Constraint] 
constraints s = sortBy length3rd 
    [(r,c, freeAtPos' s (r,c) sudokuConstraints) | 
                       (r,c) <- openPositions s ]

but why not refactor the code

prune :: (Row,Column,Value) 
      -> [Constraint] -> [Constraint]
prune _ [] = []
prune (r,c,v) ((x,y,zs):rest)
  | r == x = (x,y,zs\\[v]) : prune (r,c,v) rest
  | c == y = (x,y,zs\\[v]) : prune (r,c,v) rest
  | sameblock (r,c) (x,y) = 
        (x,y,zs\\[v]) : prune (r,c,v) rest
  | otherwise = (x,y,zs) : prune (r,c,v) rest

sameblock :: (Row,Column) -> (Row,Column) -> Bool
sameblock (r,c) (x,y) = bl r == bl x && bl c == bl y 

I see you understand this, but you are on the half way.

Exercise 4

Nice reasoning. But still sudoko's with 4 empty blocks and an unique solution exists.

| 8 6   |     3 |       |
| 3     | 4   1 |       |
|     9 |       |       |
+-------+-------+-------+
|       |     6 |       |
|       |       |       |
|       | 5     |       |
+-------+-------+-------+
|   2 3 |       |     8 |
|   8   |       |   9 3 |
| 5     |       | 7   2 |
+-------+-------+-------+
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

1 participant